[PATCH] json: Avoid calling strlen(NULL)

Subject: [PATCH] json: Avoid calling strlen(NULL)

Date: Tue, 06 Apr 2010 08:25:22 +0100

To: notmuch

Cc:

From: David Edmondson


commit b65817262b3a275ecd0ef1898d92ec5508a9f810
Author: David Edmondson <dme@dme.org>
Date:   Tue Apr 6 08:24:00 2010 +0100

    json: Avoid calling strlen(NULL)
    
    MIME parts may have no filename, which previously resulted in calling
    strlen(NULL).

	Modified json.c
diff --git a/json.c b/json.c
index f90b0fa..b73f22a 100644
--- a/json.c
+++ b/json.c
@@ -105,5 +105,8 @@ json_quote_chararray(const void *ctx, const char *str, const size_t len)
 char *
 json_quote_str(const void *ctx, const char *str)
 {
+    if (str == NULL)
+	return (char *)"\"\"";
+
     return (json_quote_chararray (ctx, str, strlen (str)));
 }


dme.
-- 
David Edmondson, http://dme.org

Thread: