Robustify parsing of numbers from strings
* defs.h (string_to_uint): New prototype.
* util.c (string_to_uint): New function.
* strace.c (error_opt_arg): New function.
(process_opt_p_list): Use string_to_uint instead of atoi.
Terminate in case of invalid process id.
(init): Use string_to_uint instead of atoi.
Use error_opt_arg in case of invalid option argument.
* syscall.c (qual_syscall, qual_signal, qual_desc): Use string_to_uint
instead of atoi.
diff --git a/syscall.c b/syscall.c
index c4ac977..cf9cd08 100644
--- a/syscall.c
+++ b/syscall.c
@@ -338,7 +338,7 @@
int rc = -1;
if (*s >= '0' && *s <= '9') {
- int i = atoi(s);
+ int i = string_to_uint(s);
if (i < 0 || i >= MAX_QUALS)
return -1;
qualify_one(i, bitflag, not, -1);
@@ -375,7 +375,7 @@
int i;
if (*s >= '0' && *s <= '9') {
- int signo = atoi(s);
+ int signo = string_to_uint(s);
if (signo < 0 || signo >= MAX_QUALS)
return -1;
qualify_one(signo, bitflag, not, -1);
@@ -402,7 +402,7 @@
qual_desc(const char *s, int bitflag, int not)
{
if (*s >= '0' && *s <= '9') {
- int desc = atoi(s);
+ int desc = string_to_uint(s);
if (desc < 0 || desc >= MAX_QUALS)
return -1;
qualify_one(desc, bitflag, not, -1);