From: Tay Ray Chuan <rctay89@gmail.com>
To: git@vger.kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH 2/2] remote-curl.c: fix rpc_out()
Date: Mon, 23 Nov 2009 11:03:38 +0800 [thread overview]
Message-ID: <20091123110338.2b230359.rctay89@gmail.com> (raw)
Use comparisons between rpc->len and rpc->pos, rather than computing
their difference. This avoids potential errors when this value is
negative and we access it.
Use an int to store the return value from packet_read_line(), instead
of a size_t.
Handle the errorneous condition where rpc->pos exceeds rpc->len by
printing a message and aborting the transfer (return 0).
Remove extraneous semicolon (';') at the end of the if statement, that
prevented code in its block from executing.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
Users might experience issues when pushing with chunked encoding when
size_t avail is negative.
remote-curl.c | 17 +++++++++++------
1 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index 69eaf58..a2b8bbf 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -297,17 +297,22 @@ static size_t rpc_out(void *ptr, size_t eltsize,
{
size_t max = eltsize * nmemb;
struct rpc_state *rpc = buffer_;
- size_t avail = rpc->len - rpc->pos;
+ size_t avail = (size_t) 0;
- if (!avail) {
- avail = packet_read_line(rpc->out, rpc->buf, rpc->alloc);
- if (!avail)
+ if (rpc->pos == rpc->len) {
+ int n = packet_read_line(rpc->out, rpc->buf, rpc->alloc);
+ if (!n)
return 0;
rpc->pos = 0;
- rpc->len = avail;
+ avail = rpc->len = (size_t) n;
+ } else if (rpc->pos > rpc->len) {
+ error("bad condition!");
+ return 0;
+ } else {
+ avail = rpc->len - rpc->pos;
}
- if (max < avail);
+ if (max < avail)
avail = max;
memcpy(ptr, rpc->buf + rpc->pos, avail);
rpc->pos += avail;
--
1.6.5.3.301.gb2eb
next reply other threads:[~2009-11-23 3:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-23 3:03 Tay Ray Chuan [this message]
2009-11-23 5:53 ` [PATCH 2/2] remote-curl.c: fix rpc_out() Sverre Rabbelier
2009-11-23 8:38 ` Tay Ray Chuan
2009-11-23 10:39 ` Johannes Schindelin
2009-11-23 17:54 ` Tay Ray Chuan
2009-11-23 21:04 ` Shawn O. Pearce
2009-11-24 1:35 ` Tay Ray Chuan
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=20091123110338.2b230359.rctay89@gmail.com \
--to=rctay89@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=spearce@spearce.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.