]> rtime.felk.cvut.cz Git - notmuch.git/commitdiff
lib: Fix potential invalid read past an empty string
authorTodd <todd@electricoding.com>
Sat, 17 Jan 2015 15:51:45 +0000 (09:51 -0600)
committerDavid Bremner <david@tethera.net>
Mon, 19 Jan 2015 07:15:05 +0000 (08:15 +0100)
==22884== ERROR: AddressSanitizer: heap-buffer-overflow on address 0x601600008291 at pc 0x7ff6295680e5 bp 0x7fff4ab9aa40 sp 0x7fff4ab9aa08
READ of size 1 at 0x601600008291 thread T0
    #0 0x7ff6295680e4 in __interceptor_strcmp ??:?
    #1 0x44763b in _thread_add_message /home/todd/.apps/notmuch/lib/thread.cc:255
    #2 0x4459e8 in notmuch_threads_get /home/todd/.apps/notmuch/lib/query.cc:496
    #3 0x41e2a7 in do_search_threads /home/todd/.apps/notmuch/notmuch-search.c:131
    #4 0x40a408 in main /home/todd/.apps/notmuch/notmuch.c:345
    #5 0x7ff627cb9ec4 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287
    #6 0x40abf3 in _start ??:?
0x601600008291 is located 0 bytes to the right of 97-byte region [0x601600008230,0x601600008291)
allocated by thread T0 here:
    #0 0x7ff62956e41a in malloc ??:?
    #1 0x7ff628b8ab5d in talloc_strdup ??:?

lib/thread.cc

index 45425056034fca555d8c679d670800872813ba13..4c49f980c7b81ee5cb92198d68bf65b8173e8cba 100644 (file)
@@ -251,8 +251,8 @@ _thread_add_message (notmuch_thread_t *thread,
                 term != NULL;
                 term = term->next)
            {
-               /* We ignore initial 'K'. */
-               if (strcmp(tag, (term->string + 1)) == 0) {
+               /* Check for an empty string, and then ignore initial 'K'. */
+               if (*(term->string) && strcmp(tag, (term->string + 1)) == 0) {
                    message_excluded = TRUE;
                    break;
                }