diff options
author | Mark Wielaard <mjw@redhat.com> | 2014-01-02 21:17:18 +0100 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2014-01-02 21:17:18 +0100 |
commit | 68de442d13f7b3192d0b81634c0f2136002c4552 (patch) | |
tree | 94b8c5087bbe4123580c7f4b1b131e44e77d5c76 | |
parent | 19108019192ab273c53ae324be448d29dac806ca (diff) | |
download | elfutils-68de442d13f7b3192d0b81634c0f2136002c4552.tar.gz |
libdwfl: linux-pid-attach.c (dwfl_linux_proc_attach): Use and check strtol
Signed-off-by: Mark Wielaard <mjw@redhat.com>
-rw-r--r-- | libdwfl/ChangeLog | 4 | ||||
-rw-r--r-- | libdwfl/linux-pid-attach.c | 11 |
2 files changed, 13 insertions, 2 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 2190899e..766fb18a 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2014-01-02 Mark Wielaard <mjw@redhat.com> + + * linux-pid-attach.c (dwfl_linux_proc_attach): Use strtol, not atoi. + 2013-12-30 Mark Wielaard <mjw@redhat.com> * argp-std.c (parse_opt): Call dwfl_linux_proc_attach and diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c index 21ff4b99..58d6942f 100644 --- a/libdwfl/linux-pid-attach.c +++ b/libdwfl/linux-pid-attach.c @@ -306,8 +306,15 @@ dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid, bool assume_ptrace_stopped) while (getline (&line, &linelen, procfile) >= 0) if (strncmp (line, "Tgid:", 5) == 0) { - pid = atoi (&line[5]); - break; + errno = 0; + char *endptr; + long val = strtol (&line[5], &endptr, 10); + if ((errno == ERANGE && val == LONG_MAX) + || *endptr != '\n' || val < 0 || val != (pid_t) val) + pid = 0; + else + pid = (pid_t) val; + break; } free (line); fclose (procfile); |