Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/116127/?format=api
http://patches.dpdk.org/api/patches/116127/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/20220909093523.471727-4-bruce.richardson@intel.com/", "project": { "id": 1, "url": "http://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<20220909093523.471727-4-bruce.richardson@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/20220909093523.471727-4-bruce.richardson@intel.com", "date": "2022-09-09T09:35:13", "name": "[v3,03/13] telemetry: fix escaping of invalid json characters", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": true, "hash": "1b64a529dd244af9ca6bc28d0effb48b32d4133a", "submitter": { "id": 20, "url": "http://patches.dpdk.org/api/people/20/?format=api", "name": "Bruce Richardson", "email": "bruce.richardson@intel.com" }, "delegate": { "id": 24651, "url": "http://patches.dpdk.org/api/users/24651/?format=api", "username": "dmarchand", "first_name": "David", "last_name": "Marchand", "email": "david.marchand@redhat.com" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/20220909093523.471727-4-bruce.richardson@intel.com/mbox/", "series": [ { "id": 24617, "url": "http://patches.dpdk.org/api/series/24617/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=24617", "date": "2022-09-09T09:35:13", "name": "telemetry JSON escaping and other enhancements", "version": 3, "mbox": "http://patches.dpdk.org/series/24617/mbox/" } ], "comments": "http://patches.dpdk.org/api/patches/116127/comments/", "check": "success", "checks": "http://patches.dpdk.org/api/patches/116127/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@inbox.dpdk.org", "Delivered-To": "patchwork@inbox.dpdk.org", "Received": [ "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 451CDA00C5;\n\tFri, 9 Sep 2022 11:35:46 +0200 (CEST)", "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id DEB0340A7E;\n\tFri, 9 Sep 2022 11:35:45 +0200 (CEST)", "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n by mails.dpdk.org (Postfix) with ESMTP id 296164003F\n for <dev@dpdk.org>; Fri, 9 Sep 2022 11:35:43 +0200 (CEST)", "from orsmga004.jf.intel.com ([10.7.209.38])\n by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 09 Sep 2022 02:35:43 -0700", "from silpixa00401385.ir.intel.com ([10.237.214.161])\n by orsmga004.jf.intel.com with ESMTP; 09 Sep 2022 02:35:41 -0700" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1662716144; x=1694252144;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=eNnDeAG62U3mZwyXgXT6/8QAGFCvQwMYYrVwb1JwZNE=;\n b=hXo1c/DxW0dL1Yw7hzprR67AMOJQSTOjkpXuDHUNCo6ZP2IR7snBj3i/\n j105snlV3i+0dABspfZuUf6iRV2hSdSFr5Bu6jkasqD90mMrRj9gWLToc\n N0noMruUhsplN+bNb8Qc6aLDPeT2GLhHrdeOZQPe0HFa3NdvbVRh/h89W\n qf9YKcvSQohvXvBfPpTeIdjZN6NHIm0KOJHP0CogDArFEm6ooELjlMaqi\n lRBucpfs1UW5WozG7IkQ7LoE9baXSVZMpFMDg8iNN1HcvMLyxiyVU+s4b\n pQNay/DaSWVRzlPAi1VL77oueLR7W4qEp5ryzq4UhHYNQMdBE/MQqD42o w==;", "X-IronPort-AV": [ "E=McAfee;i=\"6500,9779,10464\"; a=\"297437120\"", "E=Sophos;i=\"5.93,302,1654585200\"; d=\"scan'208\";a=\"297437120\"", "E=Sophos;i=\"5.93,302,1654585200\"; d=\"scan'208\";a=\"740996357\"" ], "X-ExtLoop1": "1", "From": "Bruce Richardson <bruce.richardson@intel.com>", "To": "dev@dpdk.org", "Cc": "Bruce Richardson <bruce.richardson@intel.com>,\n Ciara Power <ciara.power@intel.com>,\n =?utf-8?q?Morten_Br=C3=B8rup?= <mb@smartsharesystems.com>", "Subject": "[PATCH v3 03/13] telemetry: fix escaping of invalid json characters", "Date": "Fri, 9 Sep 2022 10:35:13 +0100", "Message-Id": "<20220909093523.471727-4-bruce.richardson@intel.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20220909093523.471727-1-bruce.richardson@intel.com>", "References": "<20220623164245.561371-1-bruce.richardson@intel.com>\n <20220909093523.471727-1-bruce.richardson@intel.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org" }, "content": "For string values returned from telemetry, escape any values that cannot\nnormally appear in a json string. According to the json spec[1], the\ncharacters than need to be handled are control chars (char value < 0x20)\nand '\"' and '\\' characters.\n\nTo handle this, we replace the snprintf call with a separate string\ncopying and encapsulation routine which checks each character as it\ncopies it to the final array.\n\n[1] https://www.rfc-editor.org/rfc/rfc8259.txt\n\nFixes: 6dd571fd07c3 (\"telemetry: introduce new functionality\")\nBugzilla ID: 1037\n\nSigned-off-by: Bruce Richardson <bruce.richardson@intel.com>\nAcked-by: Ciara Power <ciara.power@intel.com>\nAcked-by: Morten Brørup <mb@smartsharesystems.com>\n---\n lib/telemetry/telemetry.c | 11 +++++---\n lib/telemetry/telemetry_json.h | 48 +++++++++++++++++++++++++++++++++-\n 2 files changed, 55 insertions(+), 4 deletions(-)", "diff": "diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c\nindex c6fd03a5ab..7188b1905c 100644\n--- a/lib/telemetry/telemetry.c\n+++ b/lib/telemetry/telemetry.c\n@@ -232,9 +232,14 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)\n \t\t\t\tMAX_CMD_LEN, cmd ? cmd : \"none\");\n \t\tbreak;\n \tcase RTE_TEL_STRING:\n-\t\tused = snprintf(out_buf, sizeof(out_buf), \"{\\\"%.*s\\\":\\\"%.*s\\\"}\",\n-\t\t\t\tMAX_CMD_LEN, cmd,\n-\t\t\t\tRTE_TEL_MAX_SINGLE_STRING_LEN, d->data.str);\n+\t\tprefix_used = snprintf(out_buf, sizeof(out_buf), \"{\\\"%.*s\\\":\",\n+\t\t\t\tMAX_CMD_LEN, cmd);\n+\t\tcb_data_buf = &out_buf[prefix_used];\n+\t\tbuf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */\n+\n+\t\tused = rte_tel_json_str(cb_data_buf, buf_len, 0, d->data.str);\n+\t\tused += prefix_used;\n+\t\tused += strlcat(out_buf + used, \"}\", sizeof(out_buf) - used);\n \t\tbreak;\n \tcase RTE_TEL_DICT:\n \t\tprefix_used = snprintf(out_buf, sizeof(out_buf), \"{\\\"%.*s\\\":\",\ndiff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.h\nindex db70690274..13df5d07e3 100644\n--- a/lib/telemetry/telemetry_json.h\n+++ b/lib/telemetry/telemetry_json.h\n@@ -44,6 +44,52 @@ __json_snprintf(char *buf, const int len, const char *format, ...)\n \treturn 0; /* nothing written or modified */\n }\n \n+static const char control_chars[0x20] = {\n+\t\t['\\n'] = 'n',\n+\t\t['\\r'] = 'r',\n+\t\t['\\t'] = 't',\n+};\n+\n+/**\n+ * @internal\n+ * Does the same as __json_snprintf(buf, len, \"\\\"%s\\\"\", str)\n+ * except that it does proper escaping as necessary.\n+ * Drops any invalid characters we don't support\n+ */\n+static inline int\n+__json_format_str(char *buf, const int len, const char *str)\n+{\n+\tchar tmp[len];\n+\tint tmpidx = 0;\n+\n+\ttmp[tmpidx++] = '\"';\n+\twhile (*str != '\\0') {\n+\t\tif (*str < (int)RTE_DIM(control_chars)) {\n+\t\t\tint idx = *str; /* compilers don't like char type as index */\n+\t\t\tif (control_chars[idx] != 0) {\n+\t\t\t\ttmp[tmpidx++] = '\\\\';\n+\t\t\t\ttmp[tmpidx++] = control_chars[idx];\n+\t\t\t}\n+\t\t} else if (*str == '\"' || *str == '\\\\') {\n+\t\t\ttmp[tmpidx++] = '\\\\';\n+\t\t\ttmp[tmpidx++] = *str;\n+\t\t} else\n+\t\t\ttmp[tmpidx++] = *str;\n+\t\t/* we always need space for closing quote and null character.\n+\t\t * Ensuring at least two free characters also means we can always take an\n+\t\t * escaped character like \"\\n\" without overflowing\n+\t\t */\n+\t\tif (tmpidx > len - 2)\n+\t\t\treturn 0;\n+\t\tstr++;\n+\t}\n+\ttmp[tmpidx++] = '\"';\n+\ttmp[tmpidx] = '\\0';\n+\n+\tstrcpy(buf, tmp);\n+\treturn tmpidx;\n+}\n+\n /* Copies an empty array into the provided buffer. */\n static inline int\n rte_tel_json_empty_array(char *buf, const int len, const int used)\n@@ -62,7 +108,7 @@ rte_tel_json_empty_obj(char *buf, const int len, const int used)\n static inline int\n rte_tel_json_str(char *buf, const int len, const int used, const char *str)\n {\n-\treturn used + __json_snprintf(buf + used, len - used, \"\\\"%s\\\"\", str);\n+\treturn used + __json_format_str(buf + used, len - used, str);\n }\n \n /* Appends a string into the JSON array in the provided buffer. */\n", "prefixes": [ "v3", "03/13" ] }{ "id": 116127, "url": "