]> granicus.if.org Git - procps-ng/commitdiff
pwdx: fails when run in a nonexistent locale
authorColin Watson <cjwatson@ubuntu.com>
Mon, 5 Aug 2013 10:52:22 +0000 (20:52 +1000)
committerCraig Small <csmall@enc.com.au>
Mon, 5 Aug 2013 10:52:22 +0000 (20:52 +1000)
pwdx rather mysteriously fails with "invalid process id" when run in a
nonexistent locale (e.g. "LC_ALL=foo pwdx $$").  This is because it
fails to obey the documented calling sequence for strtol - that is, set
errno to 0 before the call - and thus the errno from the setlocale
failure bleeds over into its check for whether strtol failed.

References: http://bugs.debian.org/718766

Signed-off-by: Craig Small <csmall@enc.com.au>
pwdx.c

diff --git a/pwdx.c b/pwdx.c
index 214275a94ec02f463da07e2aca030314d75c2104..9d4090277e683641b89bdd22b7640881c0aa16e3 100644 (file)
--- a/pwdx.c
+++ b/pwdx.c
@@ -52,6 +52,7 @@ int check_pid_argument(char *input)
 
        if (!strncmp("/proc/", input, 6))
                skip = 6;
+       errno = 0;
        pid = strtol(input + skip, &end, 10);
 
        if (errno || input + skip == end || (end && *end))