+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.
#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
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