Re: [PATCH 2/2] notmuch-restore: handle empty input file, leading blank lines and...
authorTomi Ollila <tomi.ollila@iki.fi>
Sat, 5 Jan 2013 22:11:56 +0000 (00:11 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:57 +0000 (09:52 -0800)
84/1ad5362af2e6f6f88140084ae62ac05aeb6891 [new file with mode: 0644]

diff --git a/84/1ad5362af2e6f6f88140084ae62ac05aeb6891 b/84/1ad5362af2e6f6f88140084ae62ac05aeb6891
new file mode 100644 (file)
index 0000000..0b54f16
--- /dev/null
@@ -0,0 +1,151 @@
+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 8C3A4431FAF\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Jan 2013 14:12:08 -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 U6QxXQAUoQkD for <notmuch@notmuchmail.org>;\r
+       Sat,  5 Jan 2013 14:12:05 -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 D326E431FAE\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Jan 2013 14:12:04 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id EEA8710007D;\r
+       Sun,  6 Jan 2013 00:11:56 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: david@tethera.net, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 2/2] notmuch-restore: handle empty input file,\r
+       leading blank lines and comments.\r
+In-Reply-To: <1356550593-21683-2-git-send-email-david@tethera.net>\r
+References: <1356550593-21683-1-git-send-email-david@tethera.net>\r
+       <1356550593-21683-2-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 00:11:56 +0200\r
+Message-ID: <m2wqvri8k3.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: Sat, 05 Jan 2013 22:12:08 -0000\r
+\r
+On Wed, Dec 26 2012, 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
+>  notmuch-restore.c |   17 ++++++++++++-----\r
+>  test/dump-restore |    3 ---\r
+>  2 files changed, 12 insertions(+), 8 deletions(-)\r
+>\r
+> diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+> index 9ed9b51..c93f1ac 100644\r
+> --- a/notmuch-restore.c\r
+> +++ b/notmuch-restore.c\r
+> @@ -180,11 +180,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
+> @@ -192,6 +187,18 @@ 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
+> +         (strspn (line, " \t\n") == strlen (line)));\r
+\r
+The strspn -- strlen doesn't take embedded \0:s in input line\r
+into consideration (and strlen() scans the full line again),\r
+\r
+     (strspn (line, " \t\n") == line_len));\r
+\r
+might better\r
+\r
+(if not, then  line[strspn(line, " \t\n")] == '\0'  would drop length scan)\r
+\r
+Otherwise LGTM.\r
+\r
+Tomi\r
+\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