Two more tweaks of the mountlist module:
2025-03-21 Bruno Haible <[email protected]>
mountlist: Add specification comment in .h file.
* lib/mountlist.h (read_file_system_list): Move specification to here...
* lib/mountlist.c (read_file_system_list): ...from here.
2025-03-21 Bruno Haible <[email protected]>
mountlist: Work around an strtoul() misfeature.
* lib/mountlist.c: Include c-ctype.h.
(dev_from_mount_options): Ignore the dev=... option if its value starts
with whitespace or with a + or - sign.
* modules/mountlist (Depends-on): Add c-ctype.
>From 008ff109def9bdfdd04a12355d8f4a835045ae41 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Fri, 21 Mar 2025 12:20:24 +0100
Subject: [PATCH 1/2] mountlist: Work around an strtoul() misfeature.
* lib/mountlist.c: Include c-ctype.h.
(dev_from_mount_options): Ignore the dev=... option if its value starts
with whitespace or with a + or - sign.
* modules/mountlist (Depends-on): Add c-ctype.
---
ChangeLog | 8 ++++++++
lib/mountlist.c | 31 ++++++++++++++++---------------
modules/mountlist | 1 +
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6cd99afd0d..fcb8fc2976 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-03-21 Bruno Haible <[email protected]>
+
+ mountlist: Work around an strtoul() misfeature.
+ * lib/mountlist.c: Include c-ctype.h.
+ (dev_from_mount_options): Ignore the dev=... option if its value starts
+ with whitespace or with a + or - sign.
+ * modules/mountlist (Depends-on): Add c-ctype.
+
2025-03-21 Bruno Haible <[email protected]>
mountlist: Replace a configure-time error with a compile-time error.
diff --git a/lib/mountlist.c b/lib/mountlist.c
index d52d4ffca7..6cb947daaa 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -19,20 +19,18 @@
#include "mountlist.h"
+#include <errno.h>
+#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
+#include <unistd.h>
+#include "c-ctype.h"
#include "xalloc.h"
-#include <errno.h>
-
-#include <fcntl.h>
-
-#include <unistd.h>
-
#if HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
@@ -400,15 +398,18 @@ dev_from_mount_options (char const *mount_options)
if (devopt)
{
char const *optval = devopt + sizeof dev_pattern - 1;
- char *optvalend;
- unsigned long int dev;
- errno = 0;
- dev = strtoul (optval, &optvalend, 16);
- if (optval != optvalend
- && (*optvalend == '\0' || *optvalend == ',')
- && ! (dev == ULONG_MAX && errno == ERANGE)
- && dev == (dev_t) dev)
- return dev;
+ if (c_isxdigit (*optval))
+ {
+ char *optvalend;
+ unsigned long int dev;
+ errno = 0;
+ dev = strtoul (optval, &optvalend, 16);
+ if (optval != optvalend
+ && (*optvalend == '\0' || *optvalend == ',')
+ && ! (dev == ULONG_MAX && errno == ERANGE)
+ && dev == (dev_t) dev)
+ return dev;
+ }
}
# endif
diff --git a/modules/mountlist b/modules/mountlist
index b4acef36e6..c803f5a66b 100644
--- a/modules/mountlist
+++ b/modules/mountlist
@@ -8,6 +8,7 @@ m4/fstypename.m4
m4/mountlist.m4
Depends-on:
+c-ctype
fopen-gnu
free-posix
getline
--
2.43.0
>From 195dcaf45ccce941f0345b1d4c51d66ee15b9144 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Fri, 21 Mar 2025 12:22:42 +0100
Subject: [PATCH 2/2] mountlist: Add specification comment in .h file.
* lib/mountlist.h (read_file_system_list): Move specification to here...
* lib/mountlist.c (read_file_system_list): ...from here.
---
ChangeLog | 6 ++++++
lib/mountlist.c | 6 +-----
lib/mountlist.h | 5 +++++
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fcb8fc2976..8111c9df7c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-03-21 Bruno Haible <[email protected]>
+
+ mountlist: Add specification comment in .h file.
+ * lib/mountlist.h (read_file_system_list): Move specification to here...
+ * lib/mountlist.c (read_file_system_list): ...from here.
+
2025-03-21 Bruno Haible <[email protected]>
mountlist: Work around an strtoul() misfeature.
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 6cb947daaa..fae9bb50cb 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -457,12 +457,8 @@ terminate_at_blank (char *str)
*s = '\0';
return s;
}
-#endif
-/* Return a list of the currently mounted file systems, or NULL on error.
- Add each entry to the tail of the list so that they stay in order.
- If NEED_FS_TYPE is true, ensure that the file system type fields in
- the returned list are valid. Otherwise, they might not be. */
+#endif
struct mount_entry *
read_file_system_list (bool need_fs_type)
diff --git a/lib/mountlist.h b/lib/mountlist.h
index 5b9da0846c..e8ba1d96f9 100644
--- a/lib/mountlist.h
+++ b/lib/mountlist.h
@@ -46,8 +46,13 @@ struct mount_entry
struct mount_entry *me_next;
};
+/* Return a list of the currently mounted file systems, or NULL on error.
+ Add each entry to the tail of the list so that they stay in order.
+ If NEED_FS_TYPE is true, ensure that the file system type fields in
+ the returned list are valid. Otherwise, they might not be. */
struct mount_entry *read_file_system_list (bool need_fs_type)
_GL_ATTRIBUTE_MALLOC;
+
void free_mount_entry (struct mount_entry *entry);
--
2.43.0