[pacman-dev] [PATCH] Don't walk off front of string when stripping newline
Dan McGee
dan at archlinux.org
Tue Aug 9 16:40:57 EDT 2011
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 <dan at archlinux.org>
---
lib/libalpm/util.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index bd0526c..adb1d19 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';
--
1.7.6
More information about the pacman-dev
mailing list