From 0ba767815e640fb46f28185e2e9034145bdd5e57 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Thu, 2 May 2013 13:01:47 +0300 Subject: [PATCH] Re: [PATCH 01/24] lib/message.cc: stale pointer bug --- f0/db720e680c462d2cad1417773d2ce7550002df | 109 ++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 f0/db720e680c462d2cad1417773d2ce7550002df diff --git a/f0/db720e680c462d2cad1417773d2ce7550002df b/f0/db720e680c462d2cad1417773d2ce7550002df new file mode 100644 index 000000000..308a7c16c --- /dev/null +++ b/f0/db720e680c462d2cad1417773d2ce7550002df @@ -0,0 +1,109 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 41F9F431FB6 + for ; Thu, 2 May 2013 03:01:54 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id Bq6-9iWzF6Ui for ; + Thu, 2 May 2013 03:01:50 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 9C103431FAF + for ; Thu, 2 May 2013 03:01:50 -0700 (PDT) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 336B5100044; + Thu, 2 May 2013 13:01:48 +0300 (EEST) +From: Tomi Ollila +To: Vladimir.Marek@oracle.com, notmuch@notmuchmail.org +Subject: Re: [PATCH 01/24] lib/message.cc: stale pointer bug +In-Reply-To: <1367444021-2757-1-git-send-email-Vladimir.Marek@oracle.com> +References: <1367444021-2757-1-git-send-email-Vladimir.Marek@oracle.com> +User-Agent: Notmuch/0.15.2+75~gd7fa7c4 (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +Cc: Vladimir Marek +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 02 May 2013 10:01:54 -0000 + +On Thu, May 02 2013, Vladimir.Marek@oracle.com wrote: + +> From: Vladimir Marek +> +> Xapian::TermIterator::operator* returns std::string which is destroyed +> as soon as (*i).c_str() finishes. The remembered pointer 'term' then +> references invalid memory. + +Looks to me like a good solution... + + +Tomi + +> +> Signed-off-by: Vladimir Marek +> --- +> lib/message.cc | 11 ++++++----- +> 1 file changed, 6 insertions(+), 5 deletions(-) +> +> diff --git a/lib/message.cc b/lib/message.cc +> index 8720c1b..a890550 100644 +> --- a/lib/message.cc +> +++ b/lib/message.cc +> @@ -266,18 +266,19 @@ _notmuch_message_get_term (notmuch_message_t *message, +> const char *prefix) +> { +> int prefix_len = strlen (prefix); +> - const char *term = NULL; +> + std::string term; +> char *value; +> +> i.skip_to (prefix); +> +> - if (i != end) +> - term = (*i).c_str (); +> + if (i == end) +> + return NULL; +> +> - if (!term || strncmp (term, prefix, prefix_len)) +> + term = *i; + +... hmm, a raii(?) solution above would be std::string term = *i; + +> + if (strncmp (term.c_str(), prefix, prefix_len)) +> return NULL; +> +> - value = talloc_strdup (message, term + prefix_len); +> + value = talloc_strdup (message, term.c_str() + prefix_len); +> +> #if DEBUG_DATABASE_SANITY +> i++; +> -- +> 1.7.9.2 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2