]> Savannah Git Hosting - gnulib.git/commitdiff
mountlist: Work around an strtoul() misfeature.
authorBruno Haible <bruno@clisp.org>
Fri, 21 Mar 2025 11:20:24 +0000 (12:20 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 21 Mar 2025 11:20:24 +0000 (12:20 +0100)
* 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
lib/mountlist.c
modules/mountlist

index 6cd99afd0d42ab226cb26d036c74ad8cceae0266..fcb8fc2976d40d376b618eac8c96813c0567a9fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-03-21  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        mountlist: Replace a configure-time error with a compile-time error.
index d52d4ffca72e3e9053b275dc0ed5fce3fee78c4c..6cb947daaab7e8f1712a0cd977293d7e5aa95dbb 100644 (file)
 
 #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
index b4acef36e620051fbe4c30c5a94d1a000d42dda9..c803f5a66bf4ce1c00a78b8171a808e95c4978f9 100644 (file)
@@ -8,6 +8,7 @@ m4/fstypename.m4
 m4/mountlist.m4
 
 Depends-on:
+c-ctype
 fopen-gnu
 free-posix
 getline