[PATCH 06/10] strutils: fix unsigned integer overflows [AddressSanitizer]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 include/strutils.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/strutils.h b/include/strutils.h
index cfe8a95..4d8463a 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;
 }
 
-- 
2.1.3

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux