From 44c1a903e17ad14d5ba1cd07585a7a2415eac78a Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Fri, 24 Jul 2015 17:42:59 -0400 Subject: [PATCH] Fix: pids should be numbers only MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Ruled out cases: word, number+word, word+number, number+word+number Ex: foo, 123foo, foo123, 123foo123 Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- src/bin/lttng/commands/track-untrack.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index 52442cc13..639e18481 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -96,6 +96,7 @@ int parse_pid_string(const char *_pid_string, int count = 0; int *pid_list = NULL; char *pid_string = NULL; + char *endptr; if (all && _pid_string) { ERR("An empty PID string is expected with --all"); @@ -132,13 +133,16 @@ int parse_pid_string(const char *_pid_string, while (one_pid_str != NULL) { unsigned long v; - v = strtoul(one_pid_str, NULL, 10); + errno = 0; + v = strtoul(one_pid_str, &endptr, 10); if ((v == 0 && errno == EINVAL) - || (v == ULONG_MAX && errno == ERANGE)) { + || (v == ULONG_MAX && errno == ERANGE) + || (*one_pid_str != '\0' && *endptr != '\0')){ ERR("Error parsing PID %s", one_pid_str); retval = CMD_ERROR; goto error; } + if ((long) v > INT_MAX || (int) v < 0) { ERR("Invalid PID value %ld", (long) v); retval = CMD_ERROR; -- 2.34.1