aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Mark Walters <markwalters1009@gmail.com>2012-08-08 22:23:33 +0100
committerGravatar David Bremner <bremner@debian.org>2012-08-12 21:25:01 +0200
commit94c3b40d41f1ad98719d411ef28b69075fda0579 (patch)
tree626dd70f0fc46947595312aae8c62e1320d6bf68
parent36e640852b240ad10daed626391e1b812df89200 (diff)
sprinters: bugfix when NULL passed for a string.
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.
-rw-r--r--sprinter-json.c2
-rw-r--r--sprinter-text.c2
-rw-r--r--sprinter.h4
-rwxr-xr-xtest/missing-headers2
4 files changed, 7 insertions, 3 deletions
diff --git a/sprinter-json.c b/sprinter-json.c
index c9b68353..0a077907 100644
--- a/sprinter-json.c
+++ b/sprinter-json.c
@@ -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));
}
diff --git a/sprinter-text.c b/sprinter-text.c
index dfa54b57..10343be4 100644
--- a/sprinter-text.c
+++ b/sprinter-text.c
@@ -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));
}
diff --git a/sprinter.h b/sprinter.h
index 5f431757..912a5262 100644
--- a/sprinter.h
+++ b/sprinter.h
@@ -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);
diff --git a/test/missing-headers b/test/missing-headers
index e79f9227..f14b8784 100755
--- a/test/missing-headers
+++ b/test/missing-headers
@@ -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
message}"
test_begin_subtest "Show: json"
-test_subtest_known_broken
output=$(notmuch show --format=json '*' | notmuch_json_show_sanitize)
test_expect_equal_json "$output" '
[