summaryrefslogtreecommitdiff
path: root/builtin-fetch--tool.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-02-26 11:37:43 -0800
committerJunio C Hamano <junkio@cox.net>2007-02-27 16:12:23 -0800
commitdec56c8cf1da06fe9ff4c9d3a26f74fb1ddd2fc6 (patch)
treef7d572c6ba629e81ad156d6c83e1cdd3b4644f05 /builtin-fetch--tool.c
parentdcf01c6e6b9f63d6f6239a6c6ff9f6373e4c5ff8 (diff)
downloadgit-dec56c8cf1da06fe9ff4c9d3a26f74fb1ddd2fc6.tar.gz
fetch--tool: fix uninitialized buffer when reading from stdin
The original code allocates too much space and forgets to NUL terminate the string. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-fetch--tool.c')
-rw-r--r--builtin-fetch--tool.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
index e9d16e6315..5301c3cb78 100644
--- a/builtin-fetch--tool.c
+++ b/builtin-fetch--tool.c
@@ -2,17 +2,24 @@
#include "refs.h"
#include "commit.h"
-#define CHUNK_SIZE (1048576)
+#define CHUNK_SIZE 1024
static char *get_stdin(void)
{
+ int offset = 0;
char *data = xmalloc(CHUNK_SIZE);
- int offset = 0, read = 0;
- read = xread(0, data, CHUNK_SIZE);
- while (read == CHUNK_SIZE) {
- offset += CHUNK_SIZE;
+
+ while (1) {
+ int cnt = xread(0, data + offset, CHUNK_SIZE);
+ if (cnt < 0)
+ die("error reading standard input: %s",
+ strerror(errno));
+ if (cnt == 0) {
+ data[offset] = 0;
+ break;
+ }
+ offset += cnt;
data = xrealloc(data, offset + CHUNK_SIZE);
- read = xread(0, data + offset, CHUNK_SIZE);
}
return data;
}