Skip to content

Commit 19bdd3e

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48bdf86 commit 19bdd3e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

grep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ static NORETURN void compile_regexp_failed(const struct grep_pat *p,
306306
char where[1024];
307307

308308
if (p->no)
309-
sprintf(where, "In '%s' at %d, ", p->origin, p->no);
309+
xsnprintf(where, sizeof(where), "In '%s' at %d, ", p->origin, p->no);
310310
else if (p->origin)
311-
sprintf(where, "%s, ", p->origin);
311+
xsnprintf(where, sizeof(where), "%s, ", p->origin);
312312
else
313313
where[0] = 0;
314314

0 commit comments

Comments
 (0)