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"
This commit is contained in:
commit
daf75f2e6b
17
usage.c
17
usage.c
@ -7,21 +7,19 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
|
||||||
static FILE *error_handle;
|
static FILE *error_handle;
|
||||||
static int tweaked_error_buffering;
|
|
||||||
|
|
||||||
void vreportf(const char *prefix, const char *err, va_list params)
|
void vreportf(const char *prefix, const char *err, va_list params)
|
||||||
{
|
{
|
||||||
|
char msg[4096];
|
||||||
FILE *fh = error_handle ? error_handle : stderr;
|
FILE *fh = error_handle ? error_handle : stderr;
|
||||||
|
char *p;
|
||||||
|
|
||||||
fflush(fh);
|
vsnprintf(msg, sizeof(msg), err, params);
|
||||||
if (!tweaked_error_buffering) {
|
for (p = msg; *p; p++) {
|
||||||
setvbuf(fh, NULL, _IOLBF, 0);
|
if (iscntrl(*p) && *p != '\t' && *p != '\n')
|
||||||
tweaked_error_buffering = 1;
|
*p = '?';
|
||||||
}
|
}
|
||||||
|
fprintf(fh, "%s%s\n", prefix, msg);
|
||||||
fputs(prefix, fh);
|
|
||||||
vfprintf(fh, err, params);
|
|
||||||
fputc('\n', fh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NORETURN void usage_builtin(const char *err, va_list params)
|
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)
|
void set_error_handle(FILE *fh)
|
||||||
{
|
{
|
||||||
error_handle = fh;
|
error_handle = fh;
|
||||||
tweaked_error_buffering = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NORETURN usagef(const char *err, ...)
|
void NORETURN usagef(const char *err, ...)
|
||||||
|
Loading…
Reference in New Issue
Block a user