]> git.ipfire.org Git - thirdparty/git.git/commit
usage: report vsnprintf(3) failure
authorRené Scharfe <l.s.r@web.de>
Fri, 5 Apr 2024 18:59:52 +0000 (20:59 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Apr 2024 22:16:27 +0000 (15:16 -0700)
commitc63adab96184135718debdc8c7fc53a2abd80ca8
tree22ae6a4d093f6602446c7ec3326b5ad4ac91d1eb
parent3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0
usage: report vsnprintf(3) failure

vreportf(), which is used e.g. by die() and warning() by default, calls
vsnprintf(3) to format the message to report.  If that call fails, it
only prints the prefix, e.g. "fatal: " or "warning: ".  This at least
informs users that they were supposed to get a message and reveals its
severity, but leaves them wondering what it may have been about.

Here's an example where vreportf() tries to print a message with a 2GB
string, which is too much for vsnprintf(3):

  $ perl -le 'print "create refs/heads/", "a"x2**31' | git update-ref --stdin
  fatal:

At least report the formatting error along with the offending message
(unformatted) to indicate why that message is empty.  Use fprintf(3)
instead of error() to get the message out directly and avoid recursing
back into vreportf().

With this patch we get:

  $ perl -le 'print "create refs/heads/", "a"x2**31' | git update-ref --stdin
  error: unable to format message: invalid ref format: %s
  fatal:

... which allows users to at least get an idea of what went wrong.

Suggested-by: Jeff King <peff@peff.net>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
usage.c