From: Sami Kerola Date: Sat, 22 Nov 2014 08:18:17 +0000 (+0000) Subject: strutils: fix unsigned integer overflows [AddressSanitizer] X-Git-Tag: v2.26-rc1~119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f8610ee95ebde1e436a7ce38e34a8e8e76cc6df;p=thirdparty%2Futil-linux.git strutils: fix unsigned integer overflows [AddressSanitizer] 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 --- diff --git a/include/strutils.h b/include/strutils.h index cfe8a95603..4d8463a6d7 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -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; }