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 7836D4196F0 for ; Wed, 28 Apr 2010 03:45:30 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9] autolearn=ham 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 hQAyQtKuBmfa for ; Wed, 28 Apr 2010 03:45:29 -0700 (PDT) Received: from mail-ww0-f53.google.com (mail-ww0-f53.google.com [74.125.82.53]) by olra.theworths.org (Postfix) with ESMTP id 8417D431FC1 for ; Wed, 28 Apr 2010 03:45:29 -0700 (PDT) Received: by wwb22 with SMTP id 22so14536wwb.26 for ; Wed, 28 Apr 2010 03:45:28 -0700 (PDT) Received: by 10.216.173.202 with SMTP id v52mr994449wel.200.1272451528412; Wed, 28 Apr 2010 03:45:28 -0700 (PDT) Received: from ut.hh.sledj.net (gmp-ea-fw-1.sun.com [192.18.1.36]) by mx.google.com with ESMTPS id x14sm14786052wbs.18.2010.04.28.03.45.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 28 Apr 2010 03:45:27 -0700 (PDT) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id 95BCA5940B0; Wed, 28 Apr 2010 11:45:44 +0100 (BST) From: dme@dme.org To: notmuch@notmuchmail.org Subject: [PATCH] notmuch: Fix off-by-one errors if a header is >200 characters long. Date: Wed, 28 Apr 2010 11:45:41 +0100 Message-Id: <1272451541-6479-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.0 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: Wed, 28 Apr 2010 10:45:30 -0000 From: David Edmondson If a single header is more than 200 characters long a set of 'off by one' errors cause memory corruption. When allocating memory with: a = malloc (len); the last usable byte of the memory is 'a + len - 1' rather than 'a + len'. Fix the same bug when calculating the current offset should the buffer used for collecting the output header need to be reallocated. --- This is the cause of my segmentation fault (or bus error) during `notmuch reply'. The patch is for the 0.3.1 branch, but I'd expect that it will apply cleanly to master. gmime-filter-headers.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gmime-filter-headers.c b/gmime-filter-headers.c index 2f3df80..7db3779 100644 --- a/gmime-filter-headers.c +++ b/gmime-filter-headers.c @@ -169,7 +169,7 @@ filter_filter (GMimeFilter *filter, char *inbuf, size_t inlen, size_t prespace, headers->lineptr = headers->line = malloc (headers->line_size); } lineptr = headers->lineptr; - lineend = headers->line + headers->line_size; + lineend = headers->line + headers->line_size - 1; if (lineptr == NULL) return; outptr = filter->outbuf; @@ -185,8 +185,8 @@ filter_filter (GMimeFilter *filter, char *inbuf, size_t inlen, size_t prespace, if (lineptr == lineend) { headers->line_size *= 2; headers->line = xrealloc (headers->line, headers->line_size); - lineptr = headers->line + headers->line_size / 2; - lineend = headers->line + headers->line_size; + lineptr = headers->line + (headers->line_size / 2) - 1; + lineend = headers->line + headers->line_size - 1; } if (headers->saw_nl && *inptr != ' ' && *inptr != '\t') { -- 1.7.0