encode(): fix buffer-overflow and NUL terminate it

This commit is contained in:
Hiltjo Posthuma 2017-07-22 12:29:58 +02:00 committed by Laslo Hunhold
parent 8ec042a1ba
commit c20aa17ae8

View file

@ -141,7 +141,7 @@ encode(char src[PATH_MAX], char dest[PATH_MAX])
size_t i;
char *s;
for (s = src, i = 0; *s; s++) {
for (s = src, i = 0; *s && i < (PATH_MAX - 4); s++) {
if (iscntrl(*s) || (unsigned char)*s > 127) {
i += snprintf(dest + i, PATH_MAX - i, "%%%02X",
(unsigned char)*s);
@ -150,6 +150,7 @@ encode(char src[PATH_MAX], char dest[PATH_MAX])
i++;
}
}
dest[i] = '\0';
}
static enum status