From: Nguyễn Thái Ngọc Duy Date: Thu, 19 Jan 2017 11:41:21 +0000 (+0700) Subject: color.c: fix color_parse_mem() with value_len == 0 X-Git-Tag: v2.12.0-rc0~10^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2f41bf521b5b2ffb9ea93b98e4a57bf73d70864;p=git color.c: fix color_parse_mem() with value_len == 0 In this code we want to match the word "reset". If len is zero, strncasecmp() will return zero and we incorrectly assume it's "reset" as a result. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- diff --git a/color.c b/color.c index 81c2676723..a9eadd190a 100644 --- a/color.c +++ b/color.c @@ -207,6 +207,9 @@ int color_parse_mem(const char *value, int value_len, char *dst) struct color fg = { COLOR_UNSPECIFIED }; struct color bg = { COLOR_UNSPECIFIED }; + if (!len) + return -1; + if (!strncasecmp(value, "reset", len)) { xsnprintf(dst, end - dst, GIT_COLOR_RESET); return 0;