summaryrefslogtreecommitdiff
path: root/t/t5409-colorize-remote-messages.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-08-18 16:16:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-18 16:16:48 (GMT)
commit59a255aef05633c45c780987fa0c861cda9006f2 (patch)
treeb47a7434e8bb1bdd483014cef6fdf1bbc654dafc /t/t5409-colorize-remote-messages.sh
parentbf1a11f0a100b080a25233980c14b5ae8f3a7d2d (diff)
downloadgit-59a255aef05633c45c780987fa0c861cda9006f2.zip
git-59a255aef05633c45c780987fa0c861cda9006f2.tar.gz
git-59a255aef05633c45c780987fa0c861cda9006f2.tar.bz2
sideband: do not read beyond the end of input
The caller of maybe_colorize_sideband() gives a counted buffer <src, n>, but the callee checked src[] as if it were a NUL terminated buffer. If src[] had all isspace() bytes in it, we would have made n negative, and then (1) made number of strncasecmp() calls to see if the remaining bytes in src[] matched keywords, reading beyond the end of the array (this actually happens even if n does not go negative), and/or (2) called strbuf_add() with negative count, most likely triggering the "you want to use way too much memory" error due to unsigned integer overflow. Fix both issues by making sure we do not go beyond &src[n]. In the longer term we may want to accept size_t as parameter for clarity (even though we know that a sideband message we are painting typically would fit on a line on a terminal and int is sufficient). Write it down as a NEEDSWORK comment. Helped-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t5409-colorize-remote-messages.sh')
-rwxr-xr-xt/t5409-colorize-remote-messages.sh14
1 files changed, 14 insertions, 0 deletions
diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh
index eb1b8aa..f81b681 100755
--- a/t/t5409-colorize-remote-messages.sh
+++ b/t/t5409-colorize-remote-messages.sh
@@ -15,6 +15,8 @@ test_expect_success 'setup' '
echo warning: warning
echo prefixerror: error
echo " " "error: leading space"
+ echo " "
+ echo Err
exit 0
EOF
echo 1 >file &&
@@ -44,6 +46,12 @@ test_expect_success 'whole words at line start' '
grep "prefixerror: error" decoded
'
+test_expect_success 'short line' '
+ git -C child -c color.remote=always push -f origin HEAD:short-line 2>output &&
+ test_decode_color <output >decoded &&
+ grep "remote: Err" decoded
+'
+
test_expect_success 'case-insensitive' '
git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/case-insensitive 2>output &&
cat output &&
@@ -58,6 +66,12 @@ test_expect_success 'leading space' '
grep " <BOLD;RED>error<RESET>: leading space" decoded
'
+test_expect_success 'spaces only' '
+ git -C child -c color.remote=always push -f origin HEAD:only-space 2>output &&
+ test_decode_color <output >decoded &&
+ grep "remote: " decoded
+'
+
test_expect_success 'no coloring for redirected output' '
git --git-dir child/.git push -f origin HEAD:refs/heads/redirected-output 2>output &&
test_decode_color <output >decoded &&