aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch-restore.c
diff options
context:
space:
mode:
authorGravatar David Bremner <bremner@debian.org>2012-12-26 15:36:33 -0400
committerGravatar David Bremner <bremner@debian.org>2013-01-06 10:04:19 -0400
commitd705a6a45bf691b60101203bd09a459be255dceb (patch)
tree8b6cdece4639058e6151cfefa62470ed942865b7 /notmuch-restore.c
parent4dea9bb442f18081347708bc5446db505441fbba (diff)
notmuch-restore: handle empty input file, leading blank lines and comments.
This patch corrects several undesirable behaviours: 1) Empty files were not detected, leading to buffer read overrun. 2) An initial blank line cause restore to silently abort 3) Initial comment line caused format detection to fail
Diffstat (limited to 'notmuch-restore.c')
-rw-r--r--notmuch-restore.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/notmuch-restore.c b/notmuch-restore.c
index d43546d3..f4369898 100644
--- a/notmuch-restore.c
+++ b/notmuch-restore.c
@@ -181,11 +181,6 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
argv[opt_index]);
return 1;
}
- char *p;
-
- line_len = getline (&line, &line_size, input);
- if (line_len == 0)
- return 0;
tag_ops = tag_op_list_create (ctx);
if (tag_ops == NULL) {
@@ -193,6 +188,19 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
return 1;
}
+ do {
+ line_len = getline (&line, &line_size, input);
+
+ /* empty input file not considered an error */
+ if (line_len < 0)
+ return 0;
+
+ } while ((line_len == 0) ||
+ (line[0] == '#') ||
+ /* the cast is safe because we checked about for line_len < 0 */
+ (strspn (line, " \t\n") == (unsigned)line_len));
+
+ char *p;
for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {
if (*p == '(')
input_format = DUMP_FORMAT_SUP;