git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Green, Paul" <Paul.Green@stratus.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: [PATCH] archive-tar: convert snprintf to xsnprintf
Date: Thu, 26 May 2016 00:28:08 -0400	[thread overview]
Message-ID: <20160526042807.GA6756@sigill.intra.peff.net> (raw)
In-Reply-To: <CO2PR0801MB599926424BC99D7DFC2622B8E4F0@CO2PR0801MB599.namprd08.prod.outlook.com>

On Tue, May 24, 2016 at 12:44:24AM +0000, Green, Paul wrote:

> While examining (relatively) recent changes to git, my eye happened to
> notice the following inconsistency on line 184 of the current version
> of archive-tar.c. 
> 
> -    sprintf(header->chksum, "%07o", ustar_header_chksum(header));
> +    snprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
> 
> I believe the author meant to invoke the xsnprintf function, not the
> snprintf function. I say this because all of the other references to
> sprintf were indeed changed to xsnprintf, with the necessary
> additional 2nd argument.

Yep, it was indeed just a typo. Thanks for noticing.

-- >8 --
Subject: archive-tar: convert snprintf to xsnprintf

Commit f2f0267 (archive-tar: use xsnprintf for trivial
formatting, 2015-09-24) converted cases of "sprintf" to
"xsnprintf", but accidentally left one as just "snprintf".
This meant that we could silently truncate the resulting
buffer instead of flagging an error.

In practice, this is impossible to achieve, as we are
formatting a ustar checksum, which can be at most 7
characters. But the point of xsnprintf is to document and
check for "should be impossible" conditions; this site was
just accidentally mis-converted during f2f0267.

Noticed-by: Paul Green <Paul.Green@stratus.com>
Signed-off-by: Jeff King <peff@peff.net>
---
 archive-tar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/archive-tar.c b/archive-tar.c
index 501ca97..cb99df2 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -181,7 +181,7 @@ static void prepare_header(struct archiver_args *args,
 	memcpy(header->magic, "ustar", 6);
 	memcpy(header->version, "00", 2);
 
-	snprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
+	xsnprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
 }
 
 static int write_extended_header(struct archiver_args *args,
-- 
2.9.0.rc0.307.gc679867

      reply	other threads:[~2016-05-26  4:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-24  0:44 Typo spotted in archive-tar.c Green, Paul
2016-05-26  4:28 ` Jeff King [this message]

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

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

  git send-email \
    --in-reply-to=20160526042807.GA6756@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Paul.Green@stratus.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
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 NNTP newsgroup(s).