diff mbox

[Ada] Fix PR ada/79309

Message ID 24362543.rxIXy6VFIO@polaris
State New
Headers show

Commit Message

Eric Botcazou Feb. 1, 2017, 8:36 p.m. UTC
This is the questionable string logic in __gnat_killprocesstree detected by 
the new -Wstringop-overflow= warning.  The fix is Jakub's.

Tested on x86_64-suse-linux, applied on the mainline.


2017-02-01  Eric Botcazou  <ebotcazou@adacore.com>
            Jakub Jelinek  <jakub@redhat.com>

	PR ada/79309
	* adaint.c (__gnat_killprocesstree): Fix broken string handling.
diff mbox

Patch

Index: adaint.c
===================================================================
--- adaint.c	(revision 244917)
+++ adaint.c	(working copy)
@@ -3396,14 +3396,16 @@  void __gnat_killprocesstree (int pid, in
     {
       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");