Re: [Patch v2] notmuch-restore: handle empty input file, leading blank lines and...
authorTomi Ollila <tomi.ollila@iki.fi>
Sun, 6 Jan 2013 15:28:01 +0000 (17:28 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:57 +0000 (09:52 -0800)
12/e2b1ecc8c71d3c1bac08ebe69663f71d6a558c [new file with mode: 0644]

diff --git a/12/e2b1ecc8c71d3c1bac08ebe69663f71d6a558c b/12/e2b1ecc8c71d3c1bac08ebe69663f71d6a558c
new file mode 100644 (file)
index 0000000..d705668
--- /dev/null
@@ -0,0 +1,143 @@
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A11FC431FBF\r
+       for <notmuch@notmuchmail.org>; Sun,  6 Jan 2013 07:28:12 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id ho2UNqO0ds9I for <notmuch@notmuchmail.org>;\r
+       Sun,  6 Jan 2013 07:28:11 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 99EB0431FAE\r
+       for <notmuch@notmuchmail.org>; Sun,  6 Jan 2013 07:28:11 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id 224B51000D0;\r
+       Sun,  6 Jan 2013 17:28:02 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: david@tethera.net, notmuch@notmuchmail.org\r
+Subject: Re: [Patch v2] notmuch-restore: handle empty input file,\r
+       leading blank lines and comments.\r
+In-Reply-To: <1357481096-31254-1-git-send-email-david@tethera.net>\r
+References: <m2wqvri8k3.fsf@guru.guru-group.fi>\r
+       <1357481096-31254-1-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.14+236~ge6d0259 (http://notmuchmail.org) Emacs/24.2.1\r
+       (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sun, 06 Jan 2013 17:28:01 +0200\r
+Message-ID: <m2wqvqfi0u.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 06 Jan 2013 15:28:12 -0000\r
+\r
+On Sun, Jan 06 2013, david@tethera.net wrote:\r
+\r
+> From: David Bremner <bremner@debian.org>\r
+>\r
+> This patch corrects several undesirable behaviours:\r
+>\r
+> 1) Empty files were not detected, leading to buffer read overrun.\r
+>\r
+> 2) An initial blank line cause restore to silently abort\r
+>\r
+> 3) Initial comment line caused format detection to fail\r
+> ---\r
+\r
+LGTM.\r
+\r
+Tomi\r
+\r
+>  notmuch-restore.c |   18 +++++++++++++-----\r
+>  test/dump-restore |    3 ---\r
+>  2 files changed, 13 insertions(+), 8 deletions(-)\r
+>\r
+> diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+> index d43546d..f436989 100644\r
+> --- a/notmuch-restore.c\r
+> +++ b/notmuch-restore.c\r
+> @@ -181,11 +181,6 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+>               argv[opt_index]);\r
+>      return 1;\r
+>      }\r
+> -    char *p;\r
+> -\r
+> -    line_len = getline (&line, &line_size, input);\r
+> -    if (line_len == 0)\r
+> -    return 0;\r
+>  \r
+>      tag_ops = tag_op_list_create (ctx);\r
+>      if (tag_ops == NULL) {\r
+> @@ -193,6 +188,19 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+>      return 1;\r
+>      }\r
+>  \r
+> +    do {\r
+> +    line_len = getline (&line, &line_size, input);\r
+> +\r
+> +    /* empty input file not considered an error */\r
+> +    if (line_len < 0)\r
+> +        return 0;\r
+> +\r
+> +    } while ((line_len == 0) ||\r
+> +         (line[0] == '#') ||\r
+> +         /* the cast is safe because we checked about for line_len < 0 */\r
+> +         (strspn (line, " \t\n") == (unsigned)line_len));\r
+> +\r
+> +    char *p;\r
+>      for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {\r
+>      if (*p == '(')\r
+>          input_format = DUMP_FORMAT_SUP;\r
+> diff --git a/test/dump-restore b/test/dump-restore\r
+> index c2ddb92..ae30cd1 100755\r
+> --- a/test/dump-restore\r
+> +++ b/test/dump-restore\r
+> @@ -146,13 +146,11 @@ cat <<EOF > comments-and-blanks\r
+>  EOF\r
+>  \r
+>  test_begin_subtest 'restoring empty file is not an error'\r
+> -test_subtest_known_broken\r
+>  notmuch restore < /dev/null 2>OUTPUT.$test_count\r
+>  cp /dev/null EXPECTED\r
+>  test_expect_equal_file EXPECTED OUTPUT.$test_count\r
+>  \r
+>  test_begin_subtest 'file of comments and blank lines is not an error'\r
+> -test_subtest_known_broken\r
+>  notmuch restore --input=comments-and-blanks\r
+>  ret_val=$?\r
+>  test_expect_equal "$ret_val" "0"\r
+> @@ -172,7 +170,6 @@ echo "yun1vjwegii.fsf@aiko.keithp.com (another_tag)" \\r
+>      >> leading-comments-blanks-sup\r
+>  \r
+>  test_begin_subtest 'detect format=sup with leading comments and blanks'\r
+> -test_subtest_known_broken\r
+>  notmuch restore --input=leading-comments-blanks-sup\r
+>  notmuch search --output=tags id:yun1vjwegii.fsf@aiko.keithp.com > OUTPUT.$test_count\r
+>  echo "another_tag" > EXPECTED\r
+> -- \r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r