From 96c4b1c3033e4f018ab20af5d35cf9cbd8b31cf4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 9 Aug 2011 02:34:11 -0500 Subject: Don't walk off front of string when stripping newline If the string was zero-length to begin with, or consists of only newline characters, nothing stopped us from incrementing right off the front of the string. Ensure len stays above zero the whole time. Signed-off-by: Dan McGee --- lib/libalpm/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index bd0526ce..adb1d192 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -219,7 +219,7 @@ size_t _alpm_strip_newline(char *str) return 0; } len = strlen(str); - while(str[len - 1] == '\n') { + while(len > 0 && str[len - 1] == '\n') { len--; } str[len] = '\0'; -- cgit v1.2.3-24-g4f1b