git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: Tarmigan <tarmigan+git@gmail.com>, git@vger.kernel.org
Subject: [PATCH] http-backend: Fix bad treatment of uintmax_t in Content-Length
Date: Wed, 11 Nov 2009 20:42:41 -0800	[thread overview]
Message-ID: <20091112044240.GP11919@spearce.org> (raw)
In-Reply-To: <905315640911100910r5116779eh24796fa5788f4aef@mail.gmail.com>

Our Content-Length needs to report an off_t, which could be larger
precision than size_t on this system (e.g. 32 bit binary built with
64 bit large file support).

We also shouldn't be passing a size_t parameter to printf when
we've used PRIuMAX as the format specifier.

Fix both issues by using uintmax_t for the hdr_int() routine,
allowing strbuf's size_t to automatically upcast, and off_t to
always fit.

Also fixed the copy loop we use inside of send_local_file(), we never
actually updated the size variable so we might as well not use it.

Reported-by: Tarmigan <tarmigan+git@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---

  Tarmigan <tarmigan+git@gmail.com> wrote:
  > unhappy.  Curl returns 18 (CURLE_PARTIAL_FILE), the test takes a long
  > time to fail, and the "out" file looks OK (compared to a linux machine
  > where the test passes) expect for "Content-Length: 37847251812411".
  > 
  > Digging into it a bit more with gdb, the call to hdr_int() in
  > http-backend.c looks OK, but then something goes wrong in
  > format_write().  Hmmm it looks like my setup does not like PRIuMAX
  > with size_t, which puts some garbage in the upper bytes of

  Yup, only the right fix is to keep using PRIuMAX... patch below.
  
 http-backend.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/http-backend.c b/http-backend.c
index f8ea9d7..7f48406 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -134,7 +134,7 @@ static void hdr_str(const char *name, const char *value)
 	format_write(1, "%s: %s\r\n", name, value);
 }
 
-static void hdr_int(const char *name, size_t value)
+static void hdr_int(const char *name, uintmax_t value)
 {
 	format_write(1, "%s: %" PRIuMAX "\r\n", name, value);
 }
@@ -216,7 +216,6 @@ static void send_local_file(const char *the_type, const char *name)
 	char *buf = xmalloc(buf_alloc);
 	int fd;
 	struct stat sb;
-	size_t size;
 
 	fd = open(p, O_RDONLY);
 	if (fd < 0)
@@ -224,14 +223,12 @@ static void send_local_file(const char *the_type, const char *name)
 	if (fstat(fd, &sb) < 0)
 		die_errno("Cannot stat '%s'", p);
 
-	size = xsize_t(sb.st_size);
-
-	hdr_int(content_length, size);
+	hdr_int(content_length, sb.st_size);
 	hdr_str(content_type, the_type);
 	hdr_date(last_modified, sb.st_mtime);
 	end_headers();
 
-	while (size) {
+	for (;;) {
 		ssize_t n = xread(fd, buf, buf_alloc);
 		if (n < 0)
 			die_errno("Cannot read '%s'", p);
-- 
1.6.5.2.351.g09432

  reply	other threads:[~2009-11-12  4:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-09  5:18 What's cooking in git.git (Nov 2009, #02; Sun, 08) Junio C Hamano
2009-11-09  8:08 ` Tarmigan
2009-11-09 15:29   ` Shawn O. Pearce
2009-11-10 17:10 ` Tarmigan
2009-11-12  4:42   ` Shawn O. Pearce [this message]
2009-11-14 21:49     ` [PATCH] http-backend: Fix bad treatment of uintmax_t in Content-Length Tarmigan
2009-11-15  9:08       ` Junio C Hamano

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=20091112044240.GP11919@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=tarmigan+git@gmail.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.
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).