re PR ada/79309 (incorrectly bounded calls to strncat in adaint.c)
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 1 Feb 2017 20:36:23 +0000 (20:36 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Wed, 1 Feb 2017 20:36:23 +0000 (20:36 +0000)
PR ada/79309
* adaint.c (__gnat_killprocesstree): Fix broken string handling.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r245103

gcc/ada/ChangeLog
gcc/ada/adaint.c

index 8f394b0..387cfbf 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-01  Eric Botcazou  <ebotcazou@adacore.com>
+            Jakub Jelinek  <jakub@redhat.com>
+
+       PR ada/79309
+       * adaint.c (__gnat_killprocesstree): Fix broken string handling.
+
 2017-01-25  Maxim Ostapenko  <m.ostapenko@samsung.com>
 
        PR lto/79061
index 54a1d6e..e5fea3e 100644 (file)
@@ -3396,14 +3396,16 @@ void __gnat_killprocesstree (int pid, int sig_num)
     {
       if ((d->d_type & DT_DIR) == DT_DIR)
         {
-          char statfile[64] = { 0 };
+          char statfile[64];
           int _pid, _ppid;
 
           /* read /proc/<PID>/stat */
 
-          strncpy (statfile, "/proc/", sizeof(statfile));
-          strncat (statfile, d->d_name, sizeof(statfile));
-          strncat (statfile, "/stat", sizeof(statfile));
+          if (strlen (d->d_name) >= sizeof (statfile) - sizeof ("/proc//stat"))
+            continue;
+          strcpy (statfile, "/proc/");
+          strcat (statfile, d->d_name);
+          strcat (statfile, "/stat");
 
           FILE *fd = fopen (statfile, "r");