From nobody Tue Oct 24 09:34:02 2023 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 4SF6MH0RTbz4xnT3; Tue, 24 Oct 2023 09:34:03 +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 4SF6MG6VMFz3c1c; Tue, 24 Oct 2023 09:34:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698140042; 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=w0rvgkL/fBxEh+Am3c24TvaEcou7T3Hxwsu+jmNtQRo=; b=Y1gxiYt9L9ycqhq3hoGLfrUTexeJlYnsWADdIDMUoJbL/HgUCb0ImyxuY9rbLlBo9Le4XS eZ6mSUPncl92I+rRG6FTupvVFopWl8u2EuJPwo4qxEiB7Kfsnnw6GDO/R6VMImpeeGlr0z e42Oe2IdaW147K+7q9RKUBv9WuEyTKLtKvoIlauwfmu0ERc/PchN8EBcWpW3BK6MQpvw8L IwSlzmQ/OQT8zG4h24MXoAwQQr59Pg/DO9/Io10cOdbEA9SWbXnfHlvzWt5yIN0HDXSWq2 gDLGTKmKd4YA4aOet9rPrweuOjbfj21xn4a8qgcYR9a5VWtgMOR4PqidCyqNoA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698140042; a=rsa-sha256; cv=none; b=RDLdVFEl4d97ja+Tm6EsH7ARxSL0d+EdolLL/4eIECXW7g0T94QImQWzNLd84PHfmb249q rJ4k4ZK6s3ZydmKMQ9gJujBSj/tIGgAGGq4krqG7sdU9+5CE5hIbYPLMjSF2wS3QR6tQZ+ XYcsjKKqHOxOtU/ST59l5ZI91sDBkenS1hN+gxLCkgAqnGUVMWdHdBl86hf5omrcepq6It M6WYptCJrsIKvljZuKyGwKgvTE3Af7IZOaC4sswUqMp4NwpwciAnHTfe4gtKRZWbluslMK EZxYKGgZAd0VF7c7iSju79KmhxLOrlKq59CNdlY6KLUzTLXZClA0jBlv12umzA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698140042; 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=w0rvgkL/fBxEh+Am3c24TvaEcou7T3Hxwsu+jmNtQRo=; b=mQLcEddTZOMenA46DMJZWd/kIT/zhfYu1IMrbKPbvaDOUGeG5chZoftE03Xb7fDzeD3d5O 8KSfb3FSEH7rGnUUHeY6VW7vLgGhuXaGWTDpqDex9gytb790z+S4qhBzLp4iJhQdqfs6pT RubdqKJauJcw5VbI7+QyXWAWGMTon5pY8SdMHLgZOW3Ta/wUQv0Ctht4kzngMuhfWkig/0 spoUm/IKg50d+wz/3wsCwFf1IYcpqNc1d86DH/mLebWSi/3tbuTu3tzT7uCBJvXthbTVgJ 6qVUevkhKbbYk45uqWb5xIEbIg5giD0kAimOjRFnXo7cvje1qmhBVVz3GY+9wA== 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 4SF6MG5XG1z38H; Tue, 24 Oct 2023 09:34:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39O9Y207086204; Tue, 24 Oct 2023 09:34:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39O9Y229086201; Tue, 24 Oct 2023 09:34:02 GMT (envelope-from git) Date: Tue, 24 Oct 2023 09:34:02 GMT Message-Id: <202310240934.39O9Y229086201@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 2cffb52514b0 - main - libpfctl: fix pfctl_do_ioctl() 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2cffb52514b070e716e700c7f58fdb8cd9b05335 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=2cffb52514b070e716e700c7f58fdb8cd9b05335 commit 2cffb52514b070e716e700c7f58fdb8cd9b05335 Author: Kristof Provost AuthorDate: 2023-10-23 11:43:52 +0000 Commit: Kristof Provost CommitDate: 2023-10-24 07:50:31 +0000 libpfctl: fix pfctl_do_ioctl() pfctl_do_ioctl() copies the packed request data into the request buffer and then frees it. However, it's possible for the buffer to be too small for the reply, causing us to allocate a new buffer. We then copied from the freed request, and freed it again. Do not free the request buffer until we're all the way done. PR: 274614 Reviewed by: emaste MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D42329 --- lib/libpfctl/libpfctl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c index 0360c0c63be7..22b0471e2912 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -79,7 +79,6 @@ pfctl_do_ioctl(int dev, uint cmd, size_t size, nvlist_t **nvl) retry: nv.data = malloc(size); memcpy(nv.data, data, nvlen); - free(data); nv.len = nvlen; nv.size = size; @@ -97,13 +96,15 @@ retry: if (ret == 0) { *nvl = nvlist_unpack(nv.data, nv.len, 0); if (*nvl == NULL) { - free(nv.data); - return (EIO); + ret = EIO; + goto out; } } else { ret = errno; } +out: + free(data); free(nv.data); return (ret);