]> git.notmuchmail.org Git - notmuch/commitdiff
sprinters: bugfix when NULL passed for a string.
authorMark Walters <markwalters1009@gmail.com>
Wed, 8 Aug 2012 21:23:33 +0000 (22:23 +0100)
committerDavid Bremner <bremner@debian.org>
Sun, 12 Aug 2012 19:25:01 +0000 (21:25 +0200)
The string function in a sprinter may be called with a NULL string
pointer (eg if a header is absent). This causes a segfault. We fix
this by checking for a null pointer in the string functions and update
the sprinter documentation.

At the moment some output when format=text is done directly rather than
via an sprinter: in that case a null pointer is passed to printf or
similar and a "(null)" appears in the output. That behaviour is not
changed in this patch.

sprinter-json.c
sprinter-text.c
sprinter.h
test/missing-headers

index c9b683530b08cb97d0d4689efe7d0a3fff1b5e84..0a077907cd83368c339c320968ef2b8a5e91f7d8 100644 (file)
@@ -118,6 +118,8 @@ json_string_len (struct sprinter *sp, const char *val, size_t len)
 static void
 json_string (struct sprinter *sp, const char *val)
 {
+    if (val == NULL)
+       val = "";
     json_string_len (sp, val, strlen (val));
 }
 
index dfa54b5706981293ea5cf14a91ceb28137a081fb..10343be4b4f1dafe514afa25281586631b376a89 100644 (file)
@@ -38,6 +38,8 @@ text_string_len (struct sprinter *sp, const char *val, size_t len)
 static void
 text_string (struct sprinter *sp, const char *val)
 {
+    if (val == NULL)
+       val = "";
     text_string_len (sp, val, strlen (val));
 }
 
index 5f4317570a059814922402bbe89643e6c7db00b0..912a5262a56756add44b41843ad32bb18446ad75 100644 (file)
@@ -27,7 +27,9 @@ typedef struct sprinter {
      * a list or map, followed or preceded by separators).  For string
      * and string_len, the char * must be UTF-8 encoded.  string_len
      * allows non-terminated strings and strings with embedded NULs
-     * (though the handling of the latter is format-dependent).
+     * (though the handling of the latter is format-dependent). For
+     * string (but not string_len) the string pointer passed may be
+     * NULL.
      */
     void (*string) (struct sprinter *, const char *);
     void (*string_len) (struct sprinter *, const char *, size_t);
index e79f92278a28bc0dfe7ef0b4908d2919060e6b11..f14b8784b5c70cdbf63168226d4483b1ab1d08da 100755 (executable)
@@ -29,7 +29,6 @@ thread:XXX   2001-01-05 [1/1] (null);  (inbox unread)
 thread:XXX   1970-01-01 [1/1] Notmuch Test Suite;  (inbox unread)"
 
 test_begin_subtest "Search: json"
-test_subtest_known_broken
 output=$(notmuch search --format=json '*' | notmuch_search_sanitize)
 test_expect_equal_json "$output" '
 [
@@ -93,7 +92,6 @@ Body
 \fmessage}"
 
 test_begin_subtest "Show: json"
-test_subtest_known_broken
 output=$(notmuch show --format=json '*' | notmuch_json_show_sanitize)
 test_expect_equal_json "$output" '
 [