1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

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 <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-08-09 02:34:11 -05:00
parent a42e52a09f
commit 96c4b1c303

View File

@ -219,7 +219,7 @@ size_t _alpm_strip_newline(char *str)
return 0; return 0;
} }
len = strlen(str); len = strlen(str);
while(str[len - 1] == '\n') { while(len > 0 && str[len - 1] == '\n') {
len--; len--;
} }
str[len] = '\0'; str[len] = '\0';