summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 26557fc)
raw | patch | inline | side by side (parent: 26557fc)
author | Jonathan Nieder <jrnieder@gmail.com> | |
Tue, 28 Dec 2010 10:30:54 +0000 (04:30 -0600) | ||
committer | Jonathan Nieder <jrnieder@gmail.com> | |
Tue, 22 Mar 2011 21:41:09 +0000 (16:41 -0500) |
Catch input errors and exit early enough to print a reasonable
diagnosis based on errno.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
diagnosis based on errno.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
vcs-svn/fast_export.c | patch | blob | history | |
vcs-svn/svndump.c | patch | blob | history |
diff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c
index 260cf50e7725c9199fa44134a7f3408da7cad984..07a8353c8bfaa4d320a5c2fa073d08aaaebdc5e6 100644 (file)
--- a/vcs-svn/fast_export.c
+++ b/vcs-svn/fast_export.c
printf("progress Imported commit %"PRIu32".\n\n", revision);
}
+static void die_short_read(struct line_buffer *input)
+{
+ if (buffer_ferror(input))
+ die_errno("error reading dump file");
+ die("invalid dump: unexpected end of file");
+}
+
void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
{
if (mode == REPO_MODE_LNK) {
/* svn symlink blobs start with "link " */
- buffer_skip_bytes(input, 5);
len -= 5;
+ if (buffer_skip_bytes(input, 5) != 5)
+ die_short_read(input);
}
printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
- buffer_copy_bytes(input, len);
+ if (buffer_copy_bytes(input, len) != len)
+ die_short_read(input);
fputc('\n', stdout);
}
diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c
index e6d84bada579c26cdb776569fa520103fe7d9dd2..15f822ea844ba64a12d19e02e12f244b2f99d4cb 100644 (file)
--- a/vcs-svn/svndump.c
+++ b/vcs-svn/svndump.c
}
}
+static void die_short_read(void)
+{
+ if (buffer_ferror(&input))
+ die_errno("error reading dump file");
+ die("invalid dump: unexpected end of file");
+}
+
static void read_props(void)
{
uint32_t key = ~0;
uint32_t len;
const char *val;
const char type = t[0];
+ int ch;
if (!type || t[1] != ' ')
die("invalid property line: %s\n", t);
len = atoi(&t[2]);
val = buffer_read_string(&input, len);
- buffer_skip_bytes(&input, 1); /* Discard trailing newline. */
+ if (!val || strlen(val) != len)
+ die_short_read();
+
+ /* Discard trailing newline. */
+ ch = buffer_read_char(&input);
+ if (ch == EOF)
+ die_short_read();
+ if (ch != '\n')
+ die("invalid dump: expected newline after %s", val);
switch (type) {
case 'K':
node_ctx.prop_delta = !strcmp(val, "true");
} else if (key == keys.content_length) {
len = atoi(val);
- buffer_read_line(&input);
+ t = buffer_read_line(&input);
+ if (!t)
+ die_short_read();
+ if (*t)
+ die("invalid dump: expected blank line after content length header");
if (active_ctx == REV_CTX) {
read_props();
} else if (active_ctx == NODE_CTX) {
active_ctx = REV_CTX;
} else {
fprintf(stderr, "Unexpected content length header: %"PRIu32"\n", len);
- buffer_skip_bytes(&input, len);
+ if (buffer_skip_bytes(&input, len) != len)
+ die_short_read();
}
}
}
+ if (buffer_ferror(&input))
+ die_short_read();
if (active_ctx == NODE_CTX)
handle_node();
if (active_ctx != DUMP_CTX)