From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 590A36DE01D0 for ; Sun, 7 Jan 2018 14:06:37 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[AWL=0.011, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FmWG9lTSyqj2 for ; Sun, 7 Jan 2018 14:06:36 -0800 (PST) X-Greylist: delayed 2162 seconds by postgrey-1.36 at arlo; Sun, 07 Jan 2018 14:06:35 PST Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id E171F6DE00C6 for ; Sun, 7 Jan 2018 14:06:35 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1eYIWT-0005Cl-9H; Sun, 07 Jan 2018 16:30:29 -0500 Received: (nullmailer pid 12900 invoked by uid 1000); Sun, 07 Jan 2018 21:30:28 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH] CLI/restore: handle missing keys and values in config data. Date: Sun, 7 Jan 2018 17:30:25 -0400 Message-Id: <20180107213025.12848-1-david@tethera.net> X-Mailer: git-send-email 2.15.1 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jan 2018 22:06:37 -0000 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