]> granicus.if.org Git - procps-ng/commitdiff
proc/devname.c: Never write more than "chop" (part 2).
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:21 +0000 (07:32 +1000)
"chop" is the maximum offset where the null-byte should be written;
respect this even if about to write just one (non-null) character.

proc/devname.c

index 08ed131d88d960e3a923e2513589a7af72ebebfa..368548a959ba394ed5d092056240e76e6d39e808 100644 (file)
@@ -341,7 +341,7 @@ unsigned dev_to_tty(char *restrict ret, unsigned chop, dev_t dev_t_dev, int pid,
   if(  link_name(tmp, MAJOR_OF(dev), MINOR_OF(dev), pid, "fd/255")) goto abbrev;
   // fall through if unable to find a device file
 no_tty:
-  strcpy(ret, "?");
+  strcpy(ret, chop >= 1 ? "?" : "");
   return 1;
 abbrev:
   if((flags&ABBREV_DEV) && !strncmp(tmp,"/dev/",5) && tmp[5]) tmp += 5;