[PATCH] CLI/restore: handle missing keys and values in config data.

Subject: [PATCH] CLI/restore: handle missing keys and values in config data.

Date: Sun, 7 Jan 2018 17:30:25 -0400

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


jrollins discovered that

   % echo '@#foo' | notmuch restore

currently segfaults.

Although such lines can't occur in notmuch dump output, they might be
useful for clearing config, and anyway segfaulting is not the best
error message.
---
 notmuch-restore.c | 8 ++++++++
 1 file changed, 8 insertions(+)

This should probably add a couple of tests. And maybe the commit
message should mention handling null keys.

diff --git a/notmuch-restore.c b/notmuch-restore.c
index dee19c20..3d36fc55 100644
--- a/notmuch-restore.c
+++ b/notmuch-restore.c
@@ -36,7 +36,15 @@ process_config_line (notmuch_database_t *notmuch, const char* line)
     void *local = talloc_new(NULL);
 
     key_p = strtok_len_c (line, delim, &key_len);
+    if (!key_p) {
+	fprintf (stderr, "missing config key on line %s\n", line);
+	goto DONE;
+    }
+
     val_p = strtok_len_c (key_p+key_len, delim, &val_len);
+    if (!val_p) {
+	val_p = "";
+    }
 
     key = talloc_strndup (local, key_p, key_len);
     val = talloc_strndup (local, val_p, val_len);
-- 
2.15.1

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: