Fix: pids should be numbers only
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 24 Jul 2015 21:42:59 +0000 (17:42 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 27 Jul 2015 15:48:03 +0000 (11:48 -0400)
Ruled out cases: word, number+word, word+number, number+word+number
Ex: foo, 123foo, foo123, 123foo123

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/track-untrack.c

index 52442cc1361b2e8d1d0574a35f3812996bb735a8..639e18481cf9571a21fce26b8bf00319ae77296c 100644 (file)
@@ -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;
This page took 0.033532 seconds and 4 git commands to generate.