[notmuch] [PATCH] format_part_json: part_content->data is not null terminated
Gregor Hoffleit
gregor at hoffleit.de
Thu Mar 4 02:49:48 PST 2010
In format_part_json, part_content->data is not a null terminated string.
Instead, we have to use part_content->len.
---
notmuch-show.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/notmuch-show.c b/notmuch-show.c
index 1a1d601..4b755e9 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -309,10 +309,15 @@ format_part_json (GMimeObject *part, int *part_count)
if (g_mime_content_type_is_type (content_type, "text", "*") &&
!g_mime_content_type_is_type (content_type, "text", "html"))
{
+ char *content_data;
+
show_part_content (part, stream_memory);
part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));
- printf (", \"content\": %s", json_quote_str (ctx, (char *) part_content->data));
+ content_data = talloc_size (ctx, part_content->len+1);
+ memcpy (content_data, (char *)part_content->data, part_content->len+1);
+ content_data[part_content->len] = 0;
+ printf (", \"content\": %s", json_quote_str (ctx, content_data));
}
fputs ("}", stdout);
--
1.7.0
More information about the notmuch
mailing list