]> granicus.if.org Git - procps-ng/commitdiff
proc/readproc.c: Harden simple_nextpid().
authorQualys Security Advisory <qsa@qualys.com>
Thu, 1 Jan 1970 00:00:00 +0000 (00:00 +0000)
committerCraig Small <csmall@enc.com.au>
Fri, 18 May 2018 21:32:22 +0000 (07:32 +1000)
Replace memcpy+strcpy with snprintf.

proc/readproc.c

index 18644ffb675593b2d07705241d6ef01cfbba61d2..aaa8a29c6d28e4a5783f90425ac1669aa2eab1c5 100644 (file)
@@ -1224,8 +1224,7 @@ static int simple_nextpid(PROCTAB *restrict const PT, proc_t *restrict const p)
   }
   p->tgid = strtoul(ent->d_name, NULL, 10);
   p->tid = p->tgid;
-  memcpy(path, "/proc/", 6);
-  strcpy(path+6, ent->d_name);  // trust /proc to not contain evil top-level entries
+  snprintf(path, PROCPATHLEN, "/proc/%s", ent->d_name);
   return 1;
 }