]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: linux-pid-attach.c (dwfl_linux_proc_attach): Use and check strtol
authorMark Wielaard <mjw@redhat.com>
Thu, 2 Jan 2014 20:17:18 +0000 (21:17 +0100)
committerMark Wielaard <mjw@redhat.com>
Thu, 2 Jan 2014 20:17:18 +0000 (21:17 +0100)
Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdwfl/ChangeLog
libdwfl/linux-pid-attach.c

index 2190899eed4acf1a7c80a1c761f01a0f0434bd4f..766fb18ac222d874111e4734a93bd44065d9e532 100644 (file)
@@ -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
index 21ff4b99ec1a7b155c8480827c497b9860dcfb95..58d6942fe7cf43e5351467674e66895d4b31eaaf 100644 (file)
@@ -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);