* [PATCH lttng-tools 1/2] Fix: pids should be numbers only
@ 2015-07-24 21:42 Jonathan Rajotte
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Rajotte @ 2015-07-24 21:42 UTC (permalink / raw)
To: lttng-dev; +Cc: jgalar
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>
---
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 52442cc..639e184 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.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH lttng-tools 1/2] Fix: pids should be numbers only
[not found] <1437774180-32746-1-git-send-email-jonathan.rajotte-julien@efficios.com>
@ 2015-07-28 15:51 ` Jérémie Galarneau
0 siblings, 0 replies; 2+ messages in thread
From: Jérémie Galarneau @ 2015-07-28 15:51 UTC (permalink / raw)
To: Jonathan Rajotte; +Cc: lttng-dev, Jeremie Galarneau
[-- Attachment #1.1: Type: text/plain, Size: 1987 bytes --]
Merged, thanks!
J/r/mie
On Fri, Jul 24, 2015 at 5:42 PM, Jonathan Rajotte <
jonathan.rajotte-julien@efficios.com> wrote:
> 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>
> ---
> 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 52442cc..639e184 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.1.4
>
>
--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
[-- Attachment #1.2: Type: text/html, Size: 2931 bytes --]
[-- Attachment #2: Type: text/plain, Size: 155 bytes --]
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-28 15:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-24 21:42 [PATCH lttng-tools 1/2] Fix: pids should be numbers only Jonathan Rajotte
[not found] <1437774180-32746-1-git-send-email-jonathan.rajotte-julien@efficios.com>
2015-07-28 15:51 ` Jérémie Galarneau
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.