git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] imap-send: use xsnprintf to format command
Date: Tue, 2 Apr 2024 20:47:51 -0400	[thread overview]
Message-ID: <20240403004751.GA892394@coredump.intra.peff.net> (raw)
In-Reply-To: <f9ad9f41-5b9b-474e-9818-f91fc937daae@web.de>

On Tue, Apr 02, 2024 at 04:51:05PM +0200, René Scharfe wrote:

> nfsnprintf() wraps vsnprintf(3) and reports attempts to use too small a
> buffer using BUG(), just like xsnprintf().
> 
> It has an extra check that makes sure the buffer size (converted to int)
> is positive.  vsnprintf(3) is supposed to handle a buffer size of zero
> or bigger than INT_MAX just fine, so this extra comparison doesn't make
> us any safer.  If a platform has a broken implementation, we'd need to
> work around it in our compat code.
> 
> Call xsnprintf() instead to reduce code duplication and make the caller
> slightly more readable by using this more common helper.

I think this is an improvement, and since the original also called BUG()
we are not making anything worse. But I think the original was actually
in error to do so, since it depends on user data. E.g., setting
imap.user to the output of $(perl -e 'print "a" x 1024"') results in:

  BUG: imap-send.c:511: buffer too small. Please report a bug.
  error: git-imap-send died of signal 6

Now obviously that's a dumb username, but this is the buffer used for
all IMAP commands. So conceivably long folder names, etc, do the same
thing. It's probably not a big deal in practice, but conceptually this
probably ought to be xstrfmt() and not xsnprintf().

Likewise imap-send's nfvasprintf() is basically xstrfmt(), except it
takes a va_list. So it would have to be replaced by strbuf_vaddf().

I wouldn't be surprised if there are other opportunities for string
cleanup, but I generally hoped that if we waited long enough imap-send
would just go away. ;) Either because we could get rid of the tool
entirely (though from a recent-ish search, there did not seem to be a
lot of good other tools) or because we'd just drop the old code and rely
on curl to do the heavy lifting.

All that said, I think your patch makes the world slightly better, so
I'm not opposed in the meantime.

-Peff


  reply	other threads:[~2024-04-03  0:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 14:51 [PATCH] imap-send: use xsnprintf to format command René Scharfe
2024-04-03  0:47 ` Jeff King [this message]
2024-04-03  9:25   ` René Scharfe
2024-04-03 20:32     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240403004751.GA892394@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).