Typo spotted in archive-tar.c

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Typo spotted in archive-tar.c

Green, Paul
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.

This change was applied September 24, 2015 (commit f2f026752993054c1b712b6f4ae3ff167db38cbe).

See https://github.com/git/git/commit/f2f026752993054c1b712b6f4ae3ff167db38cbe#diff-d18f7cb5411066ed8eda566b26d2570c  for the full set of related changes to archive-tar.c.

Thanks
PG
--
Sr. Technical Consultant, Stratus Technologies, Inc.
5 Mill and Main, Suite 500, Maynard, MA 01754
Office: +1 (978) 461-7557, FAX: +1 (978) 461-3610

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH] archive-tar: convert snprintf to xsnprintf

Jeff King
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 <[hidden email]>
Signed-off-by: Jeff King <[hidden email]>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html