]> git.ipfire.org Git - pakfire.git/commitdiff
config: Fix read-out-of-bounds when stripping the entire string
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Sep 2023 16:46:36 +0000 (16:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Sep 2023 17:09:21 +0000 (17:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/config.c

index b5650e7901ec35ddf1d88e8577f6917975405f87..cffa34c40e4223b2fd9cdbbe5d7fd17bdfd31d20 100644 (file)
@@ -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);