1 Return-Path: <david@tethera.net>
\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 1801F431FCF
\r
6 for <notmuch@notmuchmail.org>; Fri, 26 Dec 2014 14:03:25 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 KcCTnRPUcB45 for <notmuch@notmuchmail.org>;
\r
16 Fri, 26 Dec 2014 14:03:21 -0800 (PST)
\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])
\r
18 (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id E091C431FAF
\r
21 for <notmuch@notmuchmail.org>; Fri, 26 Dec 2014 14:03:21 -0800 (PST)
\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)
\r
23 (envelope-from <david@tethera.net>)
\r
24 id 1Y4cyc-0007qM-Vs; Fri, 26 Dec 2014 18:03:18 -0400
\r
25 Received: (nullmailer pid 3992 invoked by uid 1000); Fri, 26 Dec 2014
\r
27 From: David Bremner <david@tethera.net>
\r
28 To: Tamas Szakaly <sghctoma@gmail.com>, notmuch@notmuchmail.org
\r
29 Subject: Re: BUG: Using pointer that points to a destructed string's content
\r
30 In-Reply-To: <20141226113755.GA64154@pamparam>
\r
31 References: <20141226113755.GA64154@pamparam>
\r
32 User-Agent: Notmuch/0.19+7~g5d7f7a6 (http://notmuchmail.org) Emacs/24.4.1
\r
33 (x86_64-pc-linux-gnu)
\r
34 Date: Fri, 26 Dec 2014 23:03:13 +0100
\r
35 Message-ID: <87oaqqf4ri.fsf@maritornes.cs.unb.ca>
\r
37 Content-Type: text/plain
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Fri, 26 Dec 2014 22:03:25 -0000
\r
52 Tamas Szakaly <sghctoma@gmail.com> writes:
\r
54 > The following line is from _notmuch_message_add_directory_terms in
\r
55 > lib/message.cc (line 652 in HEAD):
\r
57 > direntry = (*i).c_str ();
\r
59 > 'i' is a Xapian::TermIterator, whose operator* returns a std::string by value.
\r
60 > This means that c_str() is called on a temporary, which is destructed after the
\r
61 > full expression (essentially the particular line in this case), so 'direntry'
\r
62 > will point to a destructed std::string's data.
\r
63 > (See https://gcc.gnu.org/onlinedocs/gcc/Temporaries.html)
\r
65 Does the following patch fix it for you? I have to double check that
\r
66 direntry wasn't needed for something, but the test suite passes ;).
\r
68 diff --git a/lib/message.cc b/lib/message.cc
\r
69 index a7a13cc..24d0d5b 100644
\r
70 --- a/lib/message.cc
\r
71 +++ b/lib/message.cc
\r
72 @@ -649,10 +649,8 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)
\r
73 /* Indicate that there are filenames remaining. */
\r
74 status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
76 - direntry = (*i).c_str ();
\r
77 - direntry += direntry_prefix_len;
\r
79 - directory_id = strtol (direntry, &colon, 10);
\r
80 + directory_id = strtol (
\r
81 + (*i).c_str () + direntry_prefix_len, &colon, 10);
\r
83 if (colon == NULL || *colon != ':')
\r
84 INTERNAL_ERROR ("malformed direntry");
\r