grep: use xsnprintf to format failure message
This looks at first glance like the sprintf can overflow our buffer, but it's actually fine; the p->origin string is something constant and small, like "command line" or "-e option". Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
48bdf86995
commit
19bdd3e7e1
4
grep.c
4
grep.c
@ -306,9 +306,9 @@ static NORETURN void compile_regexp_failed(const struct grep_pat *p,
|
|||||||
char where[1024];
|
char where[1024];
|
||||||
|
|
||||||
if (p->no)
|
if (p->no)
|
||||||
sprintf(where, "In '%s' at %d, ", p->origin, p->no);
|
xsnprintf(where, sizeof(where), "In '%s' at %d, ", p->origin, p->no);
|
||||||
else if (p->origin)
|
else if (p->origin)
|
||||||
sprintf(where, "%s, ", p->origin);
|
xsnprintf(where, sizeof(where), "%s, ", p->origin);
|
||||||
else
|
else
|
||||||
where[0] = 0;
|
where[0] = 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user