From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: Re: use after free in python notmuch2 bindings
Date: Fri, 07 Jan 2022 09:06:42 -0400 [thread overview]
Message-ID: <87o84nu23h.fsf@tethera.net> (raw)
In-Reply-To: <87sfu6utxg.fsf@tethera.net>
[-- Attachment #1: Type: text/plain, Size: 1992 bytes --]
David Bremner <david@tethera.net> writes:
> I've been attempting to port nmweb to the new bindings, but I got stuck
> on a bug that segfaults python. I attached a reduced version that
> reproduces the problem for me. It uses recent messages from the notmuch
> list; it others can't reproduce let me know and I will try to make
> something more self contained including a message set.
>
Attached is a slightly simpler (and more informative) reproducer
It produces the the following output for me
7f23164b6cd0 <notmuch2.Thread object at 0x7f23164b6cd0>
87fsqijx7u.fsf@metapensiero.it <cdata 'struct _notmuch_message *' 0x137a000>
7f23164b6a90 <NotmuchIter>
87lf0anoiv.fsf@tethera.net <cdata 'struct _notmuch_message *' 0x13636f0>
7f23164b6910 <NotmuchIter>
87bl16jezh.fsf@metapensiero.it <cdata 'struct _notmuch_message *' 0x139a6b0>
7f23164c3070 <NotmuchIter>
87bl0vlbys.fsf@powell.devork.be <cdata 'struct _notmuch_message *' 0x139b8e0>
7f23164c30d0 <NotmuchIter>
87lf0anoiv.fsf@tethera.net <cdata 'struct _notmuch_message *' 0x13636f0>
7f23164b68e0 <NotmuchIter>
87bl16jezh.fsf@metapensiero.it <cdata 'struct _notmuch_message *' 0x139a6b0>
7f23164b6a00 <NotmuchIter>
87bl0vlbys.fsf@powell.devork.be <cdata 'struct _notmuch_message *' 0x139b8e0>
zsh: IOT instruction python3 test.py
The IOT instruction is actually talloc aborting. If I leave in the call
to msg.header, it segfaults as before.
I noticed that the message struct 0x139b8e0 is visited twice, once as
part of the thread and once as part of reply-to-reply-to-reply.
I think the issue here is that bindings destroy the iterator for
replies, but the library docs say
"
* The returned list will be destroyed when the thread is
* destroyed.
"
Perhaps that needs to be worded more strongly, to forbid the user from
calling notmuch_messages_destroy. I still need to untangle the intended
ownership semantics to be sure.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: test.py --]
[-- Type: text/x-python, Size: 501 bytes --]
from notmuch2 import Database
def show_msgs(msgs, level):
print('{:s} {:x} {:s}'.format(' ' * level*4, id(msgs), str(msgs)))
for msg in msgs:
print('{:s} {:s} {:s}'.format(' ' * (level*4+2), msg.messageid, str(msg._msg_p)))
replies=msg.replies()
show_msgs(replies, level+1)
db = Database(config=Database.CONFIG.SEARCH)
msg=db.find("87fsqijx7u.fsf@metapensiero.it")
threads = db.threads(query="thread:"+msg.threadid)
thread = next (threads)
show_msgs(thread, 0)
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
next prev parent reply other threads:[~2022-01-07 13:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-02 13:51 use after free in python notmuch2 bindings David Bremner
2022-01-07 13:06 ` David Bremner [this message]
2022-01-08 14:03 ` [PATCH 1/2] test: add known broken tests for recursive traversal of replies David Bremner
2022-01-08 14:03 ` [PATCH 2/2] python-cffi: returned OwnedMessage objects from Message.replies David Bremner
2022-01-08 18:59 ` Floris Bruynooghe
2022-01-09 13:26 ` David Bremner
2022-01-11 22:02 ` Floris Bruynooghe
2022-01-12 0:55 ` David Bremner
2022-01-09 13:27 ` [PATCH 1/2] test: add known broken tests for recursive traversal of replies David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o84nu23h.fsf@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).