{"thread":{"id":"42430","subject":"Typo spotted in archive-tar.c","startedAt":"2016-05-24T00:44:24Z","lastAt":"2016-05-26T04:28:08Z","messageCount":2,"participants":["Green, Paul","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"287330","messageId":"CO2PR0801MB599926424BC99D7DFC2622B8E4F0@CO2PR0801MB599.namprd08.prod.outlook.com","threadId":"42430","inReplyTo":null,"subject":"Typo spotted in archive-tar.c","fromName":"Green, Paul","fromEmail":"paul.green@stratus.com","sentAt":"2016-05-24T00:44:24Z","receivedAt":"2016-05-24T00:44:24Z","isPatch":false,"sender":{"key":"paul.green@stratus.com","avatar":null},"body":"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. \n\n-    sprintf(header->chksum, \"%07o\", ustar_header_chksum(header));\n+    snprintf(header->chksum, sizeof(header->chksum), \"%07o\", ustar_header_chksum(header));\n\nI 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.\n\nThis change was applied September 24, 2015 (commit f2f026752993054c1b712b6f4ae3ff167db38cbe). \n\nSee https://github.com/git/git/commit/f2f026752993054c1b712b6f4ae3ff167db38cbe#diff-d18f7cb5411066ed8eda566b26d2570c  for the full set of related changes to archive-tar.c.\n\nThanks\nPG\n--\nSr. Technical Consultant, Stratus Technologies, Inc.\n5 Mill and Main, Suite 500, Maynard, MA 01754\nOffice: +1 (978) 461-7557, FAX: +1 (978) 461-3610\n"},{"id":"287549","messageId":"20160526042807.GA6756@sigill.intra.peff.net","threadId":"42430","inReplyTo":"CO2PR0801MB599926424BC99D7DFC2622B8E4F0@CO2PR0801MB599.namprd08.prod.outlook.com","subject":"[PATCH] archive-tar: convert snprintf to xsnprintf","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-05-26T04:28:08Z","receivedAt":"2016-05-26T04:28:08Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, May 24, 2016 at 12:44:24AM +0000, Green, Paul wrote:\n\n> While examining (relatively) recent changes to git, my eye happened to\n> notice the following inconsistency on line 184 of the current version\n> of archive-tar.c. \n> \n> -    sprintf(header->chksum, \"%07o\", ustar_header_chksum(header));\n> +    snprintf(header->chksum, sizeof(header->chksum), \"%07o\", ustar_header_chksum(header));\n> \n> I believe the author meant to invoke the xsnprintf function, not the\n> snprintf function. I say this because all of the other references to\n> sprintf were indeed changed to xsnprintf, with the necessary\n> additional 2nd argument.\n\nYep, it was indeed just a typo. Thanks for noticing.\n\n-- >8 --\nSubject: archive-tar: convert snprintf to xsnprintf\n\nCommit f2f0267 (archive-tar: use xsnprintf for trivial\nformatting, 2015-09-24) converted cases of \"sprintf\" to\n\"xsnprintf\", but accidentally left one as just \"snprintf\".\nThis meant that we could silently truncate the resulting\nbuffer instead of flagging an error.\n\nIn practice, this is impossible to achieve, as we are\nformatting a ustar checksum, which can be at most 7\ncharacters. But the point of xsnprintf is to document and\ncheck for \"should be impossible\" conditions; this site was\njust accidentally mis-converted during f2f0267.\n\nNoticed-by: Paul Green <Paul.Green@stratus.com>\nSigned-off-by: Jeff King <peff@peff.net>\n---\n archive-tar.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/archive-tar.c b/archive-tar.c\nindex 501ca97..cb99df2 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -181,7 +181,7 @@ static void prepare_header(struct archiver_args *args,\n \tmemcpy(header->magic, \"ustar\", 6);\n \tmemcpy(header->version, \"00\", 2);\n \n-\tsnprintf(header->chksum, sizeof(header->chksum), \"%07o\", ustar_header_chksum(header));\n+\txsnprintf(header->chksum, sizeof(header->chksum), \"%07o\", ustar_header_chksum(header));\n }\n \n static int write_extended_header(struct archiver_args *args,\n-- \n2.9.0.rc0.307.gc679867\n"}]}