database error
[notmuch-archives.git] / 84 / 1ad5362af2e6f6f88140084ae62ac05aeb6891
1 Return-Path: <tomi.ollila@iki.fi>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 8C3A4431FAF\r
6         for <notmuch@notmuchmail.org>; Sat,  5 Jan 2013 14:12:08 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id U6QxXQAUoQkD for <notmuch@notmuchmail.org>;\r
16         Sat,  5 Jan 2013 14:12:05 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id D326E431FAE\r
19         for <notmuch@notmuchmail.org>; Sat,  5 Jan 2013 14:12:04 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id EEA8710007D;\r
22         Sun,  6 Jan 2013 00:11:56 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: david@tethera.net, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH 2/2] notmuch-restore: handle empty input file,\r
26         leading blank lines and comments.\r
27 In-Reply-To: <1356550593-21683-2-git-send-email-david@tethera.net>\r
28 References: <1356550593-21683-1-git-send-email-david@tethera.net>\r
29         <1356550593-21683-2-git-send-email-david@tethera.net>\r
30 User-Agent: Notmuch/0.14+236~ge6d0259 (http://notmuchmail.org) Emacs/24.2.1\r
31         (x86_64-unknown-linux-gnu)\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
33         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
34         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
35 Date: Sun, 06 Jan 2013 00:11:56 +0200\r
36 Message-ID: <m2wqvri8k3.fsf@guru.guru-group.fi>\r
37 MIME-Version: 1.0\r
38 Content-Type: text/plain\r
39 Cc: David Bremner <bremner@debian.org>\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Sat, 05 Jan 2013 22:12:08 -0000\r
53 \r
54 On Wed, Dec 26 2012, david@tethera.net wrote:\r
55 \r
56 > From: David Bremner <bremner@debian.org>\r
57 >\r
58 > This patch corrects several undesirable behaviours:\r
59 >\r
60 > 1) Empty files were not detected, leading to buffer read overrun.\r
61 >\r
62 > 2) An initial blank line cause restore to silently abort\r
63 >\r
64 > 3) Initial comment line caused format detection to fail\r
65 > ---\r
66 >  notmuch-restore.c |   17 ++++++++++++-----\r
67 >  test/dump-restore |    3 ---\r
68 >  2 files changed, 12 insertions(+), 8 deletions(-)\r
69 >\r
70 > diff --git a/notmuch-restore.c b/notmuch-restore.c\r
71 > index 9ed9b51..c93f1ac 100644\r
72 > --- a/notmuch-restore.c\r
73 > +++ b/notmuch-restore.c\r
74 > @@ -180,11 +180,6 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
75 >                argv[opt_index]);\r
76 >       return 1;\r
77 >      }\r
78 > -    char *p;\r
79 > -\r
80 > -    line_len = getline (&line, &line_size, input);\r
81 > -    if (line_len == 0)\r
82 > -     return 0;\r
83 >  \r
84 >      tag_ops = tag_op_list_create (ctx);\r
85 >      if (tag_ops == NULL) {\r
86 > @@ -192,6 +187,18 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
87 >       return 1;\r
88 >      }\r
89 >  \r
90 > +    do {\r
91 > +     line_len = getline (&line, &line_size, input);\r
92 > +\r
93 > +     /* empty input file not considered an error */\r
94 > +     if (line_len < 0)\r
95 > +         return 0;\r
96 > +\r
97 > +    } while ((line_len == 0) ||\r
98 > +          (line[0] == '#') ||\r
99 > +          (strspn (line, " \t\n") == strlen (line)));\r
100 \r
101 The strspn -- strlen doesn't take embedded \0:s in input line\r
102 into consideration (and strlen() scans the full line again),\r
103 \r
104      (strspn (line, " \t\n") == line_len));\r
105 \r
106 might better\r
107 \r
108 (if not, then  line[strspn(line, " \t\n")] == '\0'  would drop length scan)\r
109 \r
110 Otherwise LGTM.\r
111 \r
112 Tomi\r
113 \r
114 > +\r
115 > +    char *p;\r
116 >      for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {\r
117 >       if (*p == '(')\r
118 >           input_format = DUMP_FORMAT_SUP;\r
119 > diff --git a/test/dump-restore b/test/dump-restore\r
120 > index c2ddb92..ae30cd1 100755\r
121 > --- a/test/dump-restore\r
122 > +++ b/test/dump-restore\r
123 > @@ -146,13 +146,11 @@ cat <<EOF > comments-and-blanks\r
124 >  EOF\r
125 >  \r
126 >  test_begin_subtest 'restoring empty file is not an error'\r
127 > -test_subtest_known_broken\r
128 >  notmuch restore < /dev/null 2>OUTPUT.$test_count\r
129 >  cp /dev/null EXPECTED\r
130 >  test_expect_equal_file EXPECTED OUTPUT.$test_count\r
131 >  \r
132 >  test_begin_subtest 'file of comments and blank lines is not an error'\r
133 > -test_subtest_known_broken\r
134 >  notmuch restore --input=comments-and-blanks\r
135 >  ret_val=$?\r
136 >  test_expect_equal "$ret_val" "0"\r
137 > @@ -172,7 +170,6 @@ echo "yun1vjwegii.fsf@aiko.keithp.com (another_tag)" \\r
138 >      >> leading-comments-blanks-sup\r
139 >  \r
140 >  test_begin_subtest 'detect format=sup with leading comments and blanks'\r
141 > -test_subtest_known_broken\r
142 >  notmuch restore --input=leading-comments-blanks-sup\r
143 >  notmuch search --output=tags id:yun1vjwegii.fsf@aiko.keithp.com > OUTPUT.$test_count\r
144 >  echo "another_tag" > EXPECTED\r
145 > -- \r
146 > 1.7.10.4\r
147 >\r
148 > _______________________________________________\r
149 > notmuch mailing list\r
150 > notmuch@notmuchmail.org\r
151 > http://notmuchmail.org/mailman/listinfo/notmuch\r