aboutsummaryrefslogtreecommitdiff
path: root/vcs-svn/svndump.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-12-28 04:30:54 -0600
committerJonathan Nieder <jrnieder@gmail.com>2011-03-22 16:41:09 -0500
commitc9d1c8ba059577e64fb2213cb0c5f3c4619c7519 (patch)
tree1a5fcfb13c6065ba85cd8afe8ec6e8f4dfd11e1e /vcs-svn/svndump.c
parent26557fc1b37480d184a32de025b060aa1aa231db (diff)
downloadgit-c9d1c8ba059577e64fb2213cb0c5f3c4619c7519.tar.gz
git-c9d1c8ba059577e64fb2213cb0c5f3c4619c7519.tar.xz
vcs-svn: improve reporting of input errors
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>
Diffstat (limited to 'vcs-svn/svndump.c')
-rw-r--r--vcs-svn/svndump.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c
index e6d84bada..15f822ea8 100644
--- a/vcs-svn/svndump.c
+++ b/vcs-svn/svndump.c
@@ -149,6 +149,13 @@ static void handle_property(uint32_t key, const char *val, uint32_t len,
}
}
+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;
@@ -170,12 +177,21 @@ static void read_props(void)
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':
@@ -344,7 +360,11 @@ void svndump_read(const char *url)
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) {
@@ -352,10 +372,13 @@ void svndump_read(const char *url)
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)