get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/125821/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 125821,
    "url": "http://patches.dpdk.org/api/patches/125821/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20230405160326.186921-3-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": "<20230405160326.186921-3-bruce.richardson@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20230405160326.186921-3-bruce.richardson@intel.com",
    "date": "2023-04-05T16:03:23",
    "name": "[v3,2/5] telemetry: remove variable length array in printf fn",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "cc914499a5232d32193df217d30c5aa4fd1a5e24",
    "submitter": {
        "id": 20,
        "url": "http://patches.dpdk.org/api/people/20/?format=api",
        "name": "Bruce Richardson",
        "email": "bruce.richardson@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20230405160326.186921-3-bruce.richardson@intel.com/mbox/",
    "series": [
        {
            "id": 27629,
            "url": "http://patches.dpdk.org/api/series/27629/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=27629",
            "date": "2023-04-05T16:03:21",
            "name": "telemetry: remove variable length arrays",
            "version": 3,
            "mbox": "http://patches.dpdk.org/series/27629/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/125821/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/125821/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 7B2B4428D4;\n\tWed,  5 Apr 2023 18:05:02 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 212CC42D2D;\n\tWed,  5 Apr 2023 18:04:48 +0200 (CEST)",
            "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n by mails.dpdk.org (Postfix) with ESMTP id D551842D2C\n for <dev@dpdk.org>; Wed,  5 Apr 2023 18:04:45 +0200 (CEST)",
            "from fmsmga001.fm.intel.com ([10.253.24.23])\n by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 05 Apr 2023 09:04:19 -0700",
            "from silpixa00401385.ir.intel.com ([10.237.214.40])\n by fmsmga001.fm.intel.com with ESMTP; 05 Apr 2023 09:04:18 -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=1680710686; x=1712246686;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=npRz5H/BKu267RzOeanxaLE8mYLL2/vjfd6CkcJEg44=;\n b=k5FfuajgmFkIYmAk7dBQBC1TPShAWYi8kqP9zaoRY5a1Ite3RBXj9jOp\n xEctLnG5wY8JP4wCZzReSH0kJ0eDwOMa5QwRP3F1YvAbf5ddiwW/8Pmgx\n icWRwtu5Tne/LD+9UV3UBWn2jMkNOfgxhKlTYbioiwKvpZ983jNFdOB4f\n xymkCtWekcNWsHzON8K4ECsdIfoB+5ClhYPKomKOoINLLvRTjN/NnM/Mu\n Rat4sULfuROLWSnWICQVVWvCMHsYLuyqKVnZu39HcGo2AjWh0mM0jf0Ey\n fQycv/XzpcXqUz6CE79Uq1XXKuRl6DG9Ji0OWvhkBFhnImKoXGb3dOXlD w==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6600,9927,10671\"; a=\"341218596\"",
            "E=Sophos;i=\"5.98,321,1673942400\"; d=\"scan'208\";a=\"341218596\"",
            "E=McAfee;i=\"6600,9927,10671\"; a=\"830405808\"",
            "E=Sophos;i=\"5.98,321,1673942400\"; d=\"scan'208\";a=\"830405808\""
        ],
        "X-ExtLoop1": "1",
        "From": "Bruce Richardson <bruce.richardson@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "ciara.power@intel.com, roretzla@linux.microsoft.com,\n Bruce Richardson <bruce.richardson@intel.com>",
        "Subject": "[PATCH v3 2/5] telemetry: remove variable length array in printf fn",
        "Date": "Wed,  5 Apr 2023 17:03:23 +0100",
        "Message-Id": "<20230405160326.186921-3-bruce.richardson@intel.com>",
        "X-Mailer": "git-send-email 2.37.2",
        "In-Reply-To": "<20230405160326.186921-1-bruce.richardson@intel.com>",
        "References": "<20230310181836.162336-1-bruce.richardson@intel.com>\n <20230405160326.186921-1-bruce.richardson@intel.com>",
        "MIME-Version": "1.0",
        "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": "The json_snprintf function, used to add json characters on to a buffer,\nleaving the buffer unmodified in case of error, used a variable length\narray to store the data temporarily while checking for overflow. VLAs\ncan be unsafe, and are unsupported by some compilers, so remove use of\nthe VLA.\n\nFor the normal case where there is only a small amount of existing text\nin the buffer (<4 chars) to be preserved, save that off temporarily to a\nlocal array, and restore on error. To handle cases where there is more\nthan a few characters in the buffer, we use the existing logic of doing\nthe print to a temporary buffer initially and then copying. In this\ncase, though we use malloc-allocated buffer rather than VLA.\n\nWithin the unit tests, the \"telemetry_data_autotests\" test cases - which\nmimic real telemetry use - all exercise the first path. The\ntelemetry_json_autotest cases work directly with generating json, and\nuse uninitialized buffers so also test the second, malloc-allocated\nbuffer, cases.\n\nSigned-off-by: Bruce Richardson <bruce.richardson@intel.com>\n\n---\nv3: remove use of non-standard vasprintf\n---\n lib/telemetry/telemetry_json.h | 36 ++++++++++++++++++++++++++++++----\n 1 file changed, 32 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.h\nindex 744bbfe053..1bddd124f9 100644\n--- a/lib/telemetry/telemetry_json.h\n+++ b/lib/telemetry/telemetry_json.h\n@@ -8,6 +8,7 @@\n #include <inttypes.h>\n #include <stdarg.h>\n #include <stdio.h>\n+#include <stdlib.h>\n #include <rte_common.h>\n #include <rte_telemetry.h>\n \n@@ -30,17 +31,44 @@ __rte_format_printf(3, 4)\n static inline int\n __json_snprintf(char *buf, const int len, const char *format, ...)\n {\n-\tchar tmp[len];\n \tva_list ap;\n+\tchar tmp[4];\n+\tchar *newbuf;\n \tint ret;\n \n+\tif (len == 0)\n+\t\treturn 0;\n+\n+\t/* to ensure unmodified if we overflow, we save off any values currently in buf\n+\t * before we printf, if they are short enough. We restore them on error.\n+\t */\n+\tif (strnlen(buf, sizeof(tmp)) < sizeof(tmp)) {\n+\t\tstrcpy(tmp, buf);  /* strcpy is safe as we know the length */\n+\t\tva_start(ap, format);\n+\t\tret = vsnprintf(buf, len, format, ap);\n+\t\tva_end(ap);\n+\t\tif (ret > 0 && ret < len)\n+\t\t\treturn ret;\n+\t\tstrcpy(buf, tmp);  /* restore on error */\n+\t\treturn 0;\n+\t}\n+\n+\t/* in normal operations should never hit this, but can do if buffer is\n+\t * incorrectly initialized e.g. in unit test cases\n+\t */\n+\tnewbuf = malloc(len);\n+\tif (newbuf == NULL)\n+\t\treturn 0;\n+\n \tva_start(ap, format);\n-\tret = vsnprintf(tmp, sizeof(tmp), format, ap);\n+\tret = vsnprintf(newbuf, len, format, ap);\n \tva_end(ap);\n-\tif (ret > 0 && ret < (int)sizeof(tmp) && ret < len) {\n-\t\tstrcpy(buf, tmp);\n+\tif (ret > 0 && ret < len) {\n+\t\tstrcpy(buf, newbuf);\n+\t\tfree(newbuf);\n \t\treturn ret;\n \t}\n+\tfree(newbuf);\n \treturn 0; /* nothing written or modified */\n }\n \n",
    "prefixes": [
        "v3",
        "2/5"
    ]
}