Skip to content

Commit

Permalink
grep: use xsnprintf to format failure message
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Sep 25, 2015
1 parent 48bdf86 commit 19bdd3e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ static NORETURN void compile_regexp_failed(const struct grep_pat *p,
char where[1024];

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)
sprintf(where, "%s, ", p->origin);
xsnprintf(where, sizeof(where), "%s, ", p->origin);
else
where[0] = 0;

Expand Down

0 comments on commit 19bdd3e

Please sign in to comment.