We need to make sure that 'path' still has enough space to write the
trailing NUL-byte. Without this patch it's possible to write a
NUL-byte past the end of the on-stack buffer.
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
p = PATH;
again:
i = 0;
- while (*p && *p != ':' && i < FILENAME_MAX) {
+ while (*p && *p != ':' && i < FILENAME_MAX - 1) {
path[i++] = *p++;
}
p++;
n = name;
- while (*n && i < FILENAME_MAX)
+ while (*n && i < FILENAME_MAX - 1)
path[i++] = *n++;
path[i] = '\0';