]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: (helper) improve the code converting file descriptor numbers
authorMasatake YAMATO <yamato@redhat.com>
Fri, 15 Oct 2021 17:34:38 +0000 (02:34 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 21 Oct 2021 12:06:39 +0000 (21:06 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/helpers/test_mkfds.c

index 369b291c64a58bd79b177798784ad770d12fe376..80b4ffed2f35d664f2f30176b6d3160669927662 100644 (file)
@@ -587,11 +587,16 @@ int main(int argc, char **argv)
        for (int i = 0; i < factory->N; i++) {
                char *str = argv[optind + i];
                long fd;
+               char *ep;
 
-               errno  = 0;
-               fd = strtol(str, NULL, 10);
+               errno = 0;
+               fd = strtol(str, &ep, 10);
                if (errno)
                        err(EXIT_FAILURE, "failed to convert fd number: %s", str);
+               if (ep == str)
+                       errx(EXIT_FAILURE, "failed to convert fd number: %s", str);
+               if (*ep != '\0')
+                       errx(EXIT_FAILURE, _("garbage at the end of number: %s"), str);
                if (fd < 0)
                        errx(EXIT_FAILURE, "fd number should not be negative: %s", str);
                if (fd < 3)