proc/devname.c: Never write more than "chop" (part 2).

"chop" is the maximum offset where the null-byte should be written;
respect this even if about to write just one (non-null) character.
This commit is contained in:
Qualys Security Advisory 1970-01-01 00:00:00 +00:00 committed by Craig Small
parent 6b7ceb36a4
commit 3244e7ddb0

View 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; if( link_name(tmp, MAJOR_OF(dev), MINOR_OF(dev), pid, "fd/255")) goto abbrev;
// fall through if unable to find a device file // fall through if unable to find a device file
no_tty: no_tty:
strcpy(ret, "?"); strcpy(ret, chop >= 1 ? "?" : "");
return 1; return 1;
abbrev: abbrev:
if((flags&ABBREV_DEV) && !strncmp(tmp,"/dev/",5) && tmp[5]) tmp += 5; if((flags&ABBREV_DEV) && !strncmp(tmp,"/dev/",5) && tmp[5]) tmp += 5;