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 53AEC429E25 for ; Tue, 16 Aug 2011 14:38:09 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 oQ1SUKZOHfte for ; Tue, 16 Aug 2011 14:38:08 -0700 (PDT) Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8858C431FB6 for ; Tue, 16 Aug 2011 14:38:08 -0700 (PDT) Received: by wyg36 with SMTP id 36so282360wyg.26 for ; Tue, 16 Aug 2011 14:38:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=e/foFuv/74ix7Hz5H9mTdtjiA+uEXct+reAf2lznRVQ=; b=rG7Q6Ip0JY/30isGVDXsKZ5P7rwAzLw19nOXZiiEXWNeocc/Q0o0Dz9hQya4nkGif1 CjjBJq1UH27BYiJbkZbD3G9Oc8QwYz1fOBiO7ISCPnL0pjIMBtdHD9VteJk1yOKx11k1 +ipKjV56zKh3yPLgRC7+pXf6jcowt+xftbyo4= Received: by 10.216.72.139 with SMTP id t11mr142930wed.91.1313530687323; Tue, 16 Aug 2011 14:38:07 -0700 (PDT) Received: from localhost (cpc1-sgyl2-0-0-cust47.sgyl.cable.virginmedia.com [80.192.18.48]) by mx.google.com with ESMTPS id z74sm337146weq.23.2011.08.16.14.38.03 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 16 Aug 2011 14:38:05 -0700 (PDT) From: Patrick Totzke To: notmuch@notmuchmail.org Subject: [PATCH 2/2] [python] fix unsafe utf-8 decodings Date: Tue, 16 Aug 2011 22:37:47 +0100 Message-Id: <1313530667-10648-1-git-send-email-patricktotzke@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1313155408-17156-1-git-send-email-patricktotzke@gmail.com> References: <1313155408-17156-1-git-send-email-patricktotzke@gmail.com> 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: Tue, 16 Aug 2011 21:38:09 -0000 From: pazz This prevents unsafe calls to decode for return value None in get_authors/get_subject --- bindings/python/notmuch/tag.py | 4 +++- bindings/python/notmuch/thread.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py index d6abf28..9eb9fe2 100644 --- a/bindings/python/notmuch/tag.py +++ b/bindings/python/notmuch/tag.py @@ -86,7 +86,9 @@ class Tags(object): if not nmlib.notmuch_tags_valid(self._tags): self._tags = None raise StopIteration - tag = Tags._get(self._tags).decode('utf-8') + tag = Tags._get(self._tags) + if tag: + tag = tag.decode('UTF-8') nmlib.notmuch_tags_move_to_next(self._tags) return tag diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/thread.py index 120f925..2a55bd9 100644 --- a/bindings/python/notmuch/thread.py +++ b/bindings/python/notmuch/thread.py @@ -292,7 +292,10 @@ class Thread(object): """ if self._thread is None: raise NotmuchError(STATUS.NOT_INITIALIZED) - return Thread._get_authors(self._thread).decode('UTF-8') + authors = Thread._get_authors(self._thread) + if authors: + return authors.decode('UTF-8') + return None def get_subject(self): """Returns the Subject of 'thread' @@ -302,7 +305,10 @@ class Thread(object): """ if self._thread is None: raise NotmuchError(STATUS.NOT_INITIALIZED) - return Thread._get_subject(self._thread).decode('UTF-8') + subject = Thread._get_subject(self._thread) + if subject: + return subject.decode('UTF-8') + return None def get_newest_date(self): """Returns time_t of the newest message date -- 1.7.4.1