unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Gregor Hoffleit <gregor@hoffleit.de>
To: notmuch <notmuch@notmuchmail.org>
Subject: [PATCH] format_part_json: part_content->data is not null terminated
Date: Thu, 04 Mar 2010 11:49:48 +0100	[thread overview]
Message-ID: <1267699753-sup-3919@sam.mediasupervision.de> (raw)

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

             reply	other threads:[~2010-03-04 10:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-04 10:49 Gregor Hoffleit [this message]
2010-04-01 11:40 ` [PATCH] format_part_json: part_content->data is not null terminated David Bremner
2010-04-01 11:50   ` David Edmondson
2010-04-01 12:05     ` Michal Sojka
2010-04-05  9:36       ` David Edmondson
2010-04-05 18:00         ` Carl Worth
2010-04-01 12:05     ` Gregor Hoffleit

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=1267699753-sup-3919@sam.mediasupervision.de \
    --to=gregor@hoffleit.de \
    --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).