From 008ff109def9bdfdd04a12355d8f4a835045ae41 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 21 Mar 2025 12:20:24 +0100 Subject: [PATCH] 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 + + 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 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 +#include #include #include #include #include #include +#include +#include "c-ctype.h" #include "xalloc.h" -#include - -#include - -#include - #if HAVE_SYS_PARAM_H # include #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.39.5