summaryrefslogtreecommitdiff
path: root/usage.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-01-31 13:14:56 -0800
committerJunio C Hamano <gitster@pobox.com>2017-01-31 13:14:56 -0800
commitdaf75f2e6bb9f2f723eb0532c08dd6002fb17190 (patch)
tree6ad3067774f4cb0f6c8924816ad25c5376053b67 /usage.c
parent4e59582ff70d299f5a88449891e78d15b4b3fabe (diff)
parentf290089879501a855df2eb41db5b38cb0035a765 (diff)
downloadgit-daf75f2e6bb9f2f723eb0532c08dd6002fb17190.tar.gz
Merge branch 'jk/vreport-sanitize'
An error message with an ASCII control character like '\r' in it can alter the message to hide its early part, which is problematic when a remote side gives such an error message that the local side will relay with a "remote: " prefix. * jk/vreport-sanitize: vreport: sanitize ASCII control chars Revert "vreportf: avoid intermediate buffer"
Diffstat (limited to 'usage.c')
-rw-r--r--usage.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/usage.c b/usage.c
index 17f52c1b5c..ad6d2910fb 100644
--- a/usage.c
+++ b/usage.c
@@ -7,21 +7,19 @@
#include "cache.h"
static FILE *error_handle;
-static int tweaked_error_buffering;
void vreportf(const char *prefix, const char *err, va_list params)
{
+ char msg[4096];
FILE *fh = error_handle ? error_handle : stderr;
+ char *p;
- fflush(fh);
- if (!tweaked_error_buffering) {
- setvbuf(fh, NULL, _IOLBF, 0);
- tweaked_error_buffering = 1;
+ vsnprintf(msg, sizeof(msg), err, params);
+ for (p = msg; *p; p++) {
+ if (iscntrl(*p) && *p != '\t' && *p != '\n')
+ *p = '?';
}
-
- fputs(prefix, fh);
- vfprintf(fh, err, params);
- fputc('\n', fh);
+ fprintf(fh, "%s%s\n", prefix, msg);
}
static NORETURN void usage_builtin(const char *err, va_list params)
@@ -93,7 +91,6 @@ void set_die_is_recursing_routine(int (*routine)(void))
void set_error_handle(FILE *fh)
{
error_handle = fh;
- tweaked_error_buffering = 0;
}
void NORETURN usagef(const char *err, ...)