From nobody Mon Oct 3 23:11:33 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MhGmk254dz4V1c5; Mon, 3 Oct 2022 23:11:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MhGmk1Dqqz3QrC; Mon, 3 Oct 2022 23:11:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664838694; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x3dRKRy6Dqx2kP5oq3sCoHhkORvhmjwlXMn5+Qiaocw=; b=cJejCrRFqF6G70pNCxH8xr8eepQ3bcgBYaEUqgeKExIfzNAWhBfKM0YgGTPFZH4bVAJ1YA eHgHI4uoNVgY1VmtfManGv9uKwLKpybKkIEHaul2toUZpifIRoq9Yz1AiRDJqZa7VDA0aV boA69Nvxd4ZAJ1xtpICQB2MVwOIrmtTDKqeMjUorBEFJz3197gCN8ytC1vxZOHv/zE0fA6 h3LbJsiuuVPJ2Vgy5n2mm3DGEWtYhAbFf5oJyax5BLqH9oFnIvMCgj2YF9uwIO/3Yb+90W HlEwRecmBM+Wik+RgQdH17LgA9thvYDZ79BP6UsWn/ElTfwyFdv4zmavrcXEzA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MhGmk0BNwzMgW; Mon, 3 Oct 2022 23:11:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 293NBX1K065884; Mon, 3 Oct 2022 23:11:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 293NBXHa065883; Mon, 3 Oct 2022 23:11:33 GMT (envelope-from git) Date: Mon, 3 Oct 2022 23:11:33 GMT Message-Id: <202210032311.293NBXHa065883@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 1187e46d1b38 - main - nvmecontrol wdc: Don't pass a bogus pointer to free(). List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1187e46d1b3833b9b54867a5587904c451369515 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664838694; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x3dRKRy6Dqx2kP5oq3sCoHhkORvhmjwlXMn5+Qiaocw=; b=NsLvmVN6EJrgVtAiORqyasyqxOYBbZf8XuNvLQVTw1xnyuLDhCV+LNNB8xCMtfZYfsA9eV LOkLie6m4SG5Bdsru6YXB7sxHTalo1h1h5kj/EaUTvFiz5DjIMDRN48o8g2vp4Hoy4SzhX pIcLeDRExu7dO7DSmLpCefYDhtpy5vMo/nuajDGomS9TasBcqciFKA6ABJXE0VvSxKDCPp AlL7g9/bNzfkf10LSOrOsNFu6O6f1KSkcu1O3J4rYz1znHuBJb9y1fX7+C5fCIVR3wwlFK bxq69EgV2d5Pg+J8pD/18peRAXwxYukKoHGcQIpDQg1TrYCoN3HDXPfgBz0qZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664838694; a=rsa-sha256; cv=none; b=eVHdWSoFYxixtIJaI0BgFNSeBzby5Ru1Az7yPyGBR5sZBTKD2Ce+pOezl4FjbbthWjBPsL n50A5k5gXvlNHg2/P2U+Au74enoRFR9//pyYzy6nRDL80eQ1F/I1OUiXwCzuLIPfFuZ+wo 5XtFf5JjIBww938cwACoZtABMOB6l6jVh2QlOA7LhsxIE88nRckVxG7bPKO4iEQPddGzoE 1rERN2iJ/ZfOIiZ5GHBc6OPMwpQu2PjsnGeXxYSY8FED6t2o/Oof4ZALJlFqpmGcXrNrJP NEX0IKpaTq1w5MUDWS5RPj37o5wTUYI17crFjQQV9ngp2c5h7eibqVuDgsSnBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=1187e46d1b3833b9b54867a5587904c451369515 commit 1187e46d1b3833b9b54867a5587904c451369515 Author: John Baldwin AuthorDate: 2022-10-03 23:10:44 +0000 Commit: John Baldwin CommitDate: 2022-10-03 23:10:44 +0000 nvmecontrol wdc: Don't pass a bogus pointer to free(). wdc_get_dui_log_size allocates a buffer and then advances the returned pointer. Passing this advanced pointer to free() is UB, so save the original pointer to pass to free() instead. Reviewed by: imp Reported by: GCC 12 -Wfree-nonheap-object Differential Revision: https://reviews.freebsd.org/D36827 --- sbin/nvmecontrol/modules/wdc/wdc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sbin/nvmecontrol/modules/wdc/wdc.c b/sbin/nvmecontrol/modules/wdc/wdc.c index a60f72942186..1cae15a1e54c 100644 --- a/sbin/nvmecontrol/modules/wdc/wdc.c +++ b/sbin/nvmecontrol/modules/wdc/wdc.c @@ -268,7 +268,7 @@ static void wdc_get_dui_log_size(int fd, uint32_t opcode, uint8_t data_area, uint64_t *log_size, int len_off) { - uint8_t *hdr; + uint8_t *hdr, *tofree; uint8_t max_sections; int i, j; uint16_t hdr_ver; @@ -277,7 +277,7 @@ wdc_get_dui_log_size(int fd, uint32_t opcode, uint8_t data_area, dui_size = 0; len = 1024; - hdr = (uint8_t*)malloc(len); + tofree = hdr = (uint8_t*)malloc(len); if (hdr == NULL) errx(EX_OSERR, "Can't get buffer to read header"); wdc_get_data_dui(fd, opcode, len, 0, hdr, len); @@ -315,7 +315,7 @@ wdc_get_dui_log_size(int fd, uint32_t opcode, uint8_t data_area, errx(EX_PROTOCOL, "ERROR : No valid header "); *log_size = dui_size; - free(hdr); + free(tofree); } static void