[PATCH 4/4] Update NEWS for user.other_name
[notmuch-archives.git] / 8a / a7a08a5324bfb56770480e977d27872e81e3b2
1 Return-Path: <cworth@cworth.org>\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 7EA18431FBF;\r
6         Tue,  1 Dec 2009 08:08:26 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id u43OUHOZm-y5; Tue,  1 Dec 2009 08:08:25 -0800 (PST)\r
11 Received: from yoom.home.cworth.org (localhost [127.0.0.1])\r
12         by olra.theworths.org (Postfix) with ESMTP id C96C7431FAE;\r
13         Tue,  1 Dec 2009 08:08:25 -0800 (PST)\r
14 Received: by yoom.home.cworth.org (Postfix, from userid 1000)\r
15         id 0317F254419; Tue,  1 Dec 2009 08:08:08 -0800 (PST)\r
16 From: Carl Worth <cworth@cworth.org>\r
17 To: djcb@djcbsoftware.nl, "notmuch\@notmuchmail org" <notmuch@notmuchmail.org>\r
18 In-Reply-To: <87r5rpyd4x.wl%djcb@djcbsoftware.nl>\r
19 References: <87r5rpyd4x.wl%djcb@djcbsoftware.nl>\r
20 Date: Tue, 01 Dec 2009 08:08:07 -0800\r
21 Message-ID: <87k4x6ad94.fsf@yoom.home.cworth.org>\r
22 MIME-Version: 1.0\r
23 Content-Type: multipart/signed; boundary="=-=-=";\r
24         micalg=pgp-sha1; protocol="application/pgp-signature"\r
25 Subject: Re: [notmuch] [PATCH 2/2] * avoid gcc 4.4.1 compiler warning due to\r
26  ignored 'fflush' return value\r
27 X-BeenThere: notmuch@notmuchmail.org\r
28 X-Mailman-Version: 2.1.12\r
29 Precedence: list\r
30 List-Id: "Use and development of the notmuch mail system."\r
31         <notmuch.notmuchmail.org>\r
32 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
33         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
34 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
35 List-Post: <mailto:notmuch@notmuchmail.org>\r
36 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
37 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
38         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
39 X-List-Received-Date: Tue, 01 Dec 2009 16:08:26 -0000\r
40 \r
41 --=-=-=\r
42 Content-Transfer-Encoding: quoted-printable\r
43 \r
44 On Mon, 23 Nov 2009 08:21:50 +0200, Dirk-Jan C. Binnema <djcb.bulk@gmail.co=\r
45 m> wrote:\r
46 > -#define prompt(format, ...)                          \\r
47 > -    do {                                             \\r
48 > -     printf (format, ##__VA_ARGS__);                 \\r
49 > -     fflush (stdout);                                \\r
50 > -     getline (&response, &response_size, stdin);     \\r
51 > -     chomp_newline (response);                       \\r
52 > +#define prompt(format, ...)                                  \\r
53 > +    do {                                                     \\r
54 > +     int ignored;                                            \\r
55 > +     printf (format, ##__VA_ARGS__);                         \\r
56 > +     fflush (stdout);                                        \\r
57 > +     ignored =3D getline (&response, &response_size, stdin); \\r
58 > +     chomp_newline (response);                               \\r
59 >      } while (0)\r
60 \r
61 This patch is incorrect. Ignoring the return value of getline results in\r
62 the program invoking undefined behavior by reading uninitialized\r
63 memory. This is easily tested by, for example, typing Control-D to\r
64 provide EOF to a prompt from "notmuch setup".\r
65 \r
66 How about just exiting in case of EOF as in the patch below?\r
67 \r
68 I think I'll push it now.\r
69 \r
70 =2DCarl\r
71 \r
72 commit eb0cf86c7a9d5cda464d4d36a9cac66f26b5529d\r
73 Author: Carl Worth <cworth@cworth.org>\r
74 Date:   Tue Dec 1 08:06:09 2009 -0800\r
75 \r
76     notmuch setup: Exit if EOF is encountered at any prompt.\r
77 =20=20=20=20\r
78     If the user is explicitly providing EOF, then terminating the program\r
79     is the most likely desired thing to do. This also avoids undefined\r
80     behavior from continuing with an uninitialized response after ignoring\r
81     the return value of getline().\r
82 \r
83 diff --git a/notmuch-setup.c b/notmuch-setup.c\r
84 index 5ec176d..622bbaa 100644\r
85 =2D-- a/notmuch-setup.c\r
86 +++ b/notmuch-setup.c\r
87 @@ -100,12 +100,15 @@ notmuch_setup_command (unused (void *ctx),\r
88      unsigned int i;\r
89      int is_new;\r
90 =20\r
91 =2D#define prompt(format, ...)                            \\r
92 =2D    do {                                               \\r
93 =2D       printf (format, ##__VA_ARGS__);                 \\r
94 =2D       fflush (stdout);                                \\r
95 =2D       getline (&response, &response_size, stdin);     \\r
96 =2D       chomp_newline (response);                       \\r
97 +#define prompt(format, ...)                                    \\r
98 +    do {                                                       \\r
99 +       printf (format, ##__VA_ARGS__);                         \\r
100 +       fflush (stdout);                                        \\r
101 +       if (getline (&response, &response_size, stdin) < 0) {   \\r
102 +           printf ("Exiting.\n");                              \\r
103 +           exit (1);                                           \\r
104 +       }                                                       \\r
105 +       chomp_newline (response);                               \\r
106      } while (0)\r
107 =20\r
108      config =3D notmuch_config_open (ctx, NULL, &is_new);\r
109 \r
110 --=-=-=\r
111 Content-Type: application/pgp-signature\r
112 \r
113 -----BEGIN PGP SIGNATURE-----\r
114 Version: GnuPG v1.4.10 (GNU/Linux)\r
115 \r
116 iD8DBQFLFT9n6JDdNq8qSWgRAr3qAJ4jTPCWogmUm4kzzN3usjH4+oBBoQCffYvB\r
117 qznQ5wjkFBpIfsxXDdig8f8=\r
118 =P2gw\r
119 -----END PGP SIGNATURE-----\r
120 --=-=-=--\r