]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
strutils: fix unsigned integer overflows [AddressSanitizer]
authorSami Kerola <kerolasa@iki.fi>
Sat, 22 Nov 2014 08:18:17 +0000 (08:18 +0000)
committerSami Kerola <kerolasa@iki.fi>
Fri, 19 Dec 2014 09:10:48 +0000 (09:10 +0000)
include/strutils.h:174:10: runtime error: unsigned integer overflow: 0 -
1 cannot be represented in type 'size_t' (aka 'unsigned long')

include/strutils.h:178:6: runtime error: unsigned integer overflow:
18446744073709551615 + 1 cannot be represented in type 'size_t' (aka
'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
include/strutils.h

index cfe8a95603bdc838adb3c0fbd2487c9646c59aba..4d8463a6d76fdc29591629676d6f8d8557429f55 100644 (file)
@@ -171,11 +171,14 @@ static inline size_t rtrim_whitespace(unsigned char *str)
 {
        size_t i = strlen((char *) str);
 
-       while (i--) {
-               if (!isspace(str[i]))
+       while (i) {
+               i--;
+               if (!isspace(str[i])) {
+                       i++;
                        break;
+               }
        }
-       str[++i] = '\0';
+       str[i] = '\0';
        return i;
 }