Commit 9d47cb0c authored by Sami Kerola's avatar Sami Kerola

pwdx: re-create invalid process id check

Signed-off-by: default avatarSami Kerola <kerolasa@iki.fi>
parent ab25578b
......@@ -35,6 +35,23 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
int check_pid_argument(char *input)
{
int skip = 0;
long pid;
char *end = NULL;
if (!strncmp("/proc/", input, 6))
skip = 6;
pid = strtol(input + skip, &end, 10);
if (errno || input + skip == end || (end && *end))
return 1;
if (pid < 1)
return 1;
return 0;
}
int main(int argc, char *argv[])
{
char ch;
......@@ -78,6 +95,9 @@ int main(int argc, char *argv[])
/* Constant 10 is the length of strings "/proc/" + "/cwd" + 1 */
char buf[10 + strlen(argv[i]) + 1];
if (check_pid_argument(argv[i]))
errx(EXIT_FAILURE, _("invalid process id: %s"),
argv[i]);
/*
* At this point, all arguments are in the form
* /proc/NNNN or NNNN, so a simple check based on
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment