list_config_item(list, prefix, keywords[i].keyword);
}
+static void strbuf_add_sanitized(struct strbuf *dest, const char *src, int n)
+{
+ strbuf_grow(dest, n);
+ for (; n && *src; src++, n--) {
+ if (!iscntrl(*src) || *src == '\t' || *src == '\n')
+ strbuf_addch(dest, *src);
+ else {
+ strbuf_addch(dest, '^');
+ strbuf_addch(dest, *src == 0x7f ? '?' : 0x40 + *src);
+ }
+ }
+}
+
/*
* Optionally highlight one keyword in remote output if it appears at the start
* of the line. This should be called for a single line only, which is
int i;
if (!want_color_stderr(use_sideband_colors())) {
- strbuf_add(dest, src, n);
+ strbuf_add_sanitized(dest, src, n);
return;
}
}
}
- strbuf_add(dest, src, n);
+ strbuf_add_sanitized(dest, src, n);
}
grep "<BOLD;RED>error<RESET>: error" decoded
'
+test_expect_success 'disallow (color) control sequences in sideband' '
+ write_script .git/color-me-surprised <<-\EOF &&
+ printf "error: Have you \\033[31mread\\033[m this?\\n" >&2
+ exec "$@"
+ EOF
+ test_config_global uploadPack.packObjectsHook ./color-me-surprised &&
+ test_commit need-at-least-one-commit &&
+ git clone --no-local . throw-away 2>stderr &&
+ test_decode_color <stderr >decoded &&
+ test_grep ! RED decoded
+'
+
test_done