From bf99d2243fedaeb662b5d7b20138cf2ee064a110 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 21 Apr 2020 20:43:18 +0200 Subject: [PATCH] fix #6191 --- src/curl/curl.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/curl/curl.c b/src/curl/curl.c index da486ecc1..72bb17789 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c @@ -525,6 +525,40 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job) } +/** + * Test if the given content type @a ct is JSON + * + * @param ct a content type, i.e. "application/json; charset=UTF-8" + * @return true if @a ct denotes JSON + */ +static bool +is_json (const char *ct) +{ + const char *semi; + + /* check for "application/json" exact match */ + if (0 == strcasecmp (ct, + "application/json")) + return true; + /* check for "application/json;[ANYTHING]" */ + semi = strchr (ct, + ';'); + /* also allow "application/json [ANYTHING]" (note the space!) */ + if (NULL == semi) + semi = strchr (ct, + ' '); + if (NULL == semi) + return false; /* no delimiter we accept, forget it */ + if (semi - ct != strlen ("application/json")) + return false; /* delimiter past desired length, forget it */ + if (0 == strncasecmp (ct, + "application/json", + strlen ("application/json"))) + return true; /* OK */ + return false; +} + + /** * Obtain information about the final result about the * HTTP download. If the download was successful, parses @@ -562,8 +596,7 @@ GNUNET_CURL_download_get_result_ (struct GNUNET_CURL_DownloadBuffer *db, CURLINFO_CONTENT_TYPE, &ct)) || (NULL == ct) || - (0 != strcasecmp (ct, - "application/json"))) + (! is_json (ct))) { /* No content type or explicitly not JSON, refuse to parse (but keep response code) */ -- 2.25.1