diff options
| author | Mark Wielaard <[email protected]> | 2014-01-02 21:17:18 +0100 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2014-01-02 21:17:18 +0100 |
| commit | 68de442d13f7b3192d0b81634c0f2136002c4552 (patch) | |
| tree | 94b8c5087bbe4123580c7f4b1b131e44e77d5c76 /libdwfl/linux-pid-attach.c | |
| parent | 19108019192ab273c53ae324be448d29dac806ca (diff) | |
libdwfl: linux-pid-attach.c (dwfl_linux_proc_attach): Use and check strtol
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libdwfl/linux-pid-attach.c')
| -rw-r--r-- | libdwfl/linux-pid-attach.c | 11 |
1 files changed, 9 insertions, 2 deletions
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); |
