From 260554883a251baa17187c6a655812079866a9c9 Mon Sep 17 00:00:00 2001 From: su8 Date: Wed, 8 Aug 2018 15:14:59 +0200 Subject: [PATCH] exec.cc: Add some overflow checks --- src/exec.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/exec.cc b/src/exec.cc index 6d272be7..09af3926 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -59,20 +59,23 @@ static FILE *pid_popen(const char *command, const char *mode, pid_t *child) { char *str1 = cmd; const char *str2 = command; int skip = 0; + int x = 0; - for (; *str2; str2++) { + for (; *str2; str2++, x++) { if (0 == skip) { if (*str2 == '"' || *str2 == '\'') { skip = 1; continue; } } - if ('\0' == *(str2+1)) { + if ('\0' == *(str2+1) && 1 == skip) { if (*str2 == '"' || *str2 == '\'') { continue; } } - *str1++ = *str2; + if (254 > x) { + *str1++ = *str2; + } } *str1 = '\0';