From 5c58f40bd3b8429313ac1d05311d1624e1379ba4 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Thu, 2 May 2013 19:20:30 +0300 Subject: [PATCH] Re: [PATCH] lib/message.cc: stale pointer bug (v3) --- 4b/f90a60f639af6a38b22f59f5f2d6236daec258 | 120 ++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 4b/f90a60f639af6a38b22f59f5f2d6236daec258 diff --git a/4b/f90a60f639af6a38b22f59f5f2d6236daec258 b/4b/f90a60f639af6a38b22f59f5f2d6236daec258 new file mode 100644 index 000000000..4a1686698 --- /dev/null +++ b/4b/f90a60f639af6a38b22f59f5f2d6236daec258 @@ -0,0 +1,120 @@ +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 2DF10431FB6 + for ; Thu, 2 May 2013 09:20:42 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 x5Pj5WEZ1RU6 for ; + Thu, 2 May 2013 09:20:38 -0700 (PDT) +Received: from mail-la0-f46.google.com (mail-la0-f46.google.com + [209.85.215.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id C1201431FAF + for ; Thu, 2 May 2013 09:20:37 -0700 (PDT) +Received: by mail-la0-f46.google.com with SMTP id fk20so702834lab.33 + for ; Thu, 02 May 2013 09:20:36 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=x-received:from:to:cc:subject:in-reply-to:references:user-agent + :date:message-id:mime-version:content-type:x-gm-message-state; + bh=Kbig8zRFV5QxiiFKLAkpnX13r00hHw7FkgqoUoTMZF8=; + b=VkOeMKJB8Tc3slhtvA2HfMAmbz2OlbDluD4X2Rtgz4DZ4JBh5rqCef3gQ1hNC+oI0Z + fqcEl7rxzmAH4xXFkiXz+wj7/g63sQadjhr3PX+OygkbmWHDkbv8bVYVfn+ZtR4kBLk3 + UNiKF5Kk2FjvdHmhQSyf/JawDPBPK5WXuKuEXGH1TnyaD8AMzZFrtVBzYOqbp56aqyW5 + KFQE0hHADzTVfFZhT8zxbKSw0baqHRt39Ke/sVr2aA3YpVR17kutcboHElmcfCzruNgw + lIc0B1WuH6DqNN/rBxaSa4IwnlL3waN8+lZh9x/CV7/Co3UyogwqVdxeJ3IwqYpVjdD3 + 7wrA== +X-Received: by 10.152.6.229 with SMTP id e5mr2468033laa.6.1367511636197; + Thu, 02 May 2013 09:20:36 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c376-211.dhcp.inet.fi. + [88.195.118.211]) + by mx.google.com with ESMTPSA id r9sm2970061lbr.3.2013.05.02.09.20.34 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Thu, 02 May 2013 09:20:35 -0700 (PDT) +From: Jani Nikula +To: Vladimir.Marek@oracle.com, notmuch@notmuchmail.org +Subject: Re: [PATCH] lib/message.cc: stale pointer bug (v3) +In-Reply-To: <1367505102-12860-1-git-send-email-Vladimir.Marek@oracle.com> +References: <1367505102-12860-1-git-send-email-Vladimir.Marek@oracle.com> +User-Agent: Notmuch/0.15.2+70~g2eeb96a (http://notmuchmail.org) Emacs/24.2.1 + (x86_64-pc-linux-gnu) +Date: Thu, 02 May 2013 19:20:30 +0300 +Message-ID: <87ppx94alt.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain +X-Gm-Message-State: + ALoCoQmYutxrV69Xb5RCUw7L15OCv4aoorjKzUkmv2EWs2x8XEwvHFQeLRIrgjmNLZWUGkrz3Pku +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 16:20:42 -0000 + + +LGTM + +On Thu, 02 May 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. +> +> Signed-off-by: Vladimir Marek +> --- +> lib/message.cc | 10 +++++----- +> 1 file changed, 5 insertions(+), 5 deletions(-) +> +> diff --git a/lib/message.cc b/lib/message.cc +> index 8720c1b..c4261e6 100644 +> --- a/lib/message.cc +> +++ b/lib/message.cc +> @@ -266,18 +266,18 @@ _notmuch_message_get_term (notmuch_message_t *message, +> const char *prefix) +> { +> int prefix_len = strlen (prefix); +> - const char *term = NULL; +> 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)) +> + 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