From: Michael Tremer Date: Tue, 26 Sep 2023 16:46:36 +0000 (+0000) Subject: config: Fix read-out-of-bounds when stripping the entire string X-Git-Tag: 0.9.30~1633 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=333473a3f17d45a9ea4ab371df4944b1fc107fac;p=pakfire.git config: Fix read-out-of-bounds when stripping the entire string Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/config.c b/src/libpakfire/config.c index b5650e790..cffa34c40 100644 --- a/src/libpakfire/config.c +++ b/src/libpakfire/config.c @@ -426,6 +426,8 @@ static ssize_t lstrip(char* s) { return 0; size_t l = strlen(s); + if (!l) + return 0; // Remove leading space while (isspace(s[0])) @@ -441,15 +443,19 @@ static ssize_t rstrip(char* s) { size_t l = strlen(s); // Remove trailing space - while (isspace(s[l - 1])) + while (l > 0 && isspace(s[l - 1])) s[l-- - 1] = '\0'; return l; } static ssize_t strip(char* s) { - ssize_t l = lstrip(s); + ssize_t l; + + // Strip everything on the left side + l = lstrip(s); + // Strip everything on the right side if (l) l = rstrip(s);