From nobody Fri Nov 24 14:10:46 2023 X-Original-To: dev-commits-src-all@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 4ScH2G2g58z52b1h; Fri, 24 Nov 2023 14:10:46 +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 4ScH2G1xbPz3fw9; Fri, 24 Nov 2023 14:10:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700835046; 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=yUWAjA+FBf/aX/Zk75IxO4dzFqQkwcro09T4QpmMJoQ=; b=ZTV4QIeU3YkM0qVOvc7gAtvvlvLoFh67PkwNb7fA/ol+qjqUcdKC2xWZXOHbOhc7aLwqcy piauAQn3PQmfWQaij+SQjEYUnWd1y13NLmcKWFk4eHK2LgyNwz+rPlGvWej8VeLOuO/5AE mYyh0BuZMDNP32QqpMfWtO99VDiyDrJ7d4mtitGklLzl2k8RD8MzWs70YbWZrDm108Pm3d TCw4g5k6OrQi9PHAnW1c5p8h+z35AKxlFZWPTELHu+BY3Bg7N1OhB8UWtBTxCSFMGqgsdt 8X/shZYEwfphA6Ya0a227gfTL9ojSFAVjJFRPQrg+KB6keVZrPxws0tHmvCQUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700835046; 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=yUWAjA+FBf/aX/Zk75IxO4dzFqQkwcro09T4QpmMJoQ=; b=TAvb6+wdblh68hU3Pn0CbJhpkkjPOzn11ehgHC8lQAebeYvQPQO6H+wQO1kOx0jyTfsf2/ cgvpOg9uFx2eQbg2d5mh2PXEQuRJ3PSKkHndP5TQyoCmTvaBgxvKWJnD+/VZyvn9k+0NXN 10NG33GtHM2HUoBCNqIJVxpppOyYd6j9FHoR3VpK+kgsEuCMTKS2+XMj/CHCkYa5j2mdEJ SPWc5jnCC7ZEcHMkBPytD8koUMdqvk2BpVLGhfq6wN+6z86VcKwtdqVYvDJaVeIhxU4zWf BlE9ykGFdw25PFi0Tc3JpD+QY4Gi7lWZi85BXuJchsS8nZqobysfXHiGbLsuiQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700835046; a=rsa-sha256; cv=none; b=R9n6RcbCIeq//vlam2FCRnRg9AWSaBZARnhUvtWKiBIJqxZ50nEIy51ZOg3HHgowY5sgk7 e6DRCgokIox5v+6/a3UxDVe9RVET7CfqC5Ju+qbcwq+ho0TGAIhAWew2bdfaZBKKugMXE7 tqIOl7Vli6MDSE3oULcqHMogGghUU5q9lNzOo7i+cc0xJIxwatBgUiIF8NrmBuJ93wxfwL j0Bc5YcIzxVSfiEekKJzurqEIUIyAWmRK83OL/EXtDROpEGuXH/RLMQnlem6Y+yrzboyVc wreRy8fbXke2SErPR6JprXRgrWMMa0nDwy5QU6g/RrenL38rO18lsTIkGr1P3g== 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 4ScH2G0zCdznk5; Fri, 24 Nov 2023 14:10:46 +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 3AOEAkT8024907; Fri, 24 Nov 2023 14:10:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AOEAkLr024904; Fri, 24 Nov 2023 14:10:46 GMT (envelope-from git) Date: Fri, 24 Nov 2023 14:10:46 GMT Message-Id: <202311241410.3AOEAkLr024904@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 68013761ce74 - stable/14 - libpfctl: handle pfctl_do_ioctl() failures better List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 68013761ce7403bce5ab842885eceade23488796 Auto-Submitted: auto-generated The branch stable/14 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=68013761ce7403bce5ab842885eceade23488796 commit 68013761ce7403bce5ab842885eceade23488796 Author: Kristof Provost AuthorDate: 2023-11-17 09:19:38 +0000 Commit: Kristof Provost CommitDate: 2023-11-24 09:19:13 +0000 libpfctl: handle pfctl_do_ioctl() failures better Ensure that we free nvlists and other allocations if pfctl_do_ioctl() fails. MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 498934c5ff51e6b0d3199db5d27ed11b1e8b9582) --- lib/libpfctl/libpfctl.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c index 1ef96f52c19c..f43fb78d9a0f 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -221,6 +221,7 @@ pfctl_get_status(int dev) nvl = nvlist_create(0); if (pfctl_do_ioctl(dev, DIOCGETSTATUSNV, 4096, &nvl)) { + nvlist_destroy(nvl); free(status); return (NULL); } @@ -741,12 +742,13 @@ pfctl_get_eth_rulesets_info(int dev, struct pfctl_eth_rulesets_info *ri, nvlist_add_string(nvl, "path", path); if ((ret = pfctl_do_ioctl(dev, DIOCGETETHRULESETS, 256, &nvl)) != 0) - return (ret); + goto out; ri->nr = nvlist_get_number(nvl, "nr"); +out: nvlist_destroy(nvl); - return (0); + return (ret); } int @@ -763,16 +765,16 @@ pfctl_get_eth_ruleset(int dev, const char *path, int nr, nvlist_add_number(nvl, "nr", nr); if ((ret = pfctl_do_ioctl(dev, DIOCGETETHRULESET, 1024, &nvl)) != 0) - return (ret); + goto out; ri->nr = nvlist_get_number(nvl, "nr"); strlcpy(ri->path, nvlist_get_string(nvl, "path"), MAXPATHLEN); strlcpy(ri->name, nvlist_get_string(nvl, "name"), PF_ANCHOR_NAME_SIZE); +out: nvlist_destroy(nvl); - - return (0); + return (ret); } int @@ -788,13 +790,14 @@ pfctl_get_eth_rules_info(int dev, struct pfctl_eth_rules_info *rules, nvlist_add_string(nvl, "anchor", path); if ((ret = pfctl_do_ioctl(dev, DIOCGETETHRULES, 1024, &nvl)) != 0) - return (ret); + goto out; rules->nr = nvlist_get_number(nvl, "nr"); rules->ticket = nvlist_get_number(nvl, "ticket"); +out: nvlist_destroy(nvl); - return (0); + return (ret); } int @@ -813,7 +816,7 @@ pfctl_get_eth_rule(int dev, uint32_t nr, uint32_t ticket, nvlist_add_bool(nvl, "clear", clear); if ((ret = pfctl_do_ioctl(dev, DIOCGETETHRULE, 4096, &nvl)) != 0) - return (ret); + goto out; pfctl_nveth_rule_to_eth_rule(nvl, rule); @@ -821,8 +824,9 @@ pfctl_get_eth_rule(int dev, uint32_t nr, uint32_t ticket, strlcpy(anchor_call, nvlist_get_string(nvl, "anchor_call"), MAXPATHLEN); +out: nvlist_destroy(nvl); - return (0); + return (ret); } int @@ -1079,7 +1083,7 @@ int pfctl_get_clear_rule(int dev, uint32_t nr, uint32_t ticket, nvlist_add_bool(nvl, "clear_counter", true); if ((ret = pfctl_do_ioctl(dev, DIOCGETRULENV, 8192, &nvl)) != 0) - return (ret); + goto out; pf_nvrule_to_rule(nvlist_get_nvlist(nvl, "rule"), rule); @@ -1087,9 +1091,9 @@ int pfctl_get_clear_rule(int dev, uint32_t nr, uint32_t ticket, strlcpy(anchor_call, nvlist_get_string(nvl, "anchor_call"), MAXPATHLEN); +out: nvlist_destroy(nvl); - - return (0); + return (ret); } int @@ -1284,13 +1288,13 @@ _pfctl_clear_states(int dev, const struct pfctl_kill *kill, nvlist_add_bool(nvl, "kill_match", kill->kill_match); if ((ret = pfctl_do_ioctl(dev, ioctlval, 1024, &nvl)) != 0) - return (ret); + goto out; if (killed) *killed = nvlist_get_number(nvl, "killed"); +out: nvlist_destroy(nvl); - return (ret); } @@ -1466,8 +1470,10 @@ pfctl_get_syncookies(int dev, struct pfctl_syncookies *s) nvl = nvlist_create(0); - if ((ret = pfctl_do_ioctl(dev, DIOCGETSYNCOOKIES, 256, &nvl)) != 0) - return (errno); + if ((ret = pfctl_do_ioctl(dev, DIOCGETSYNCOOKIES, 256, &nvl)) != 0) { + ret = errno; + goto out; + } enabled = nvlist_get_bool(nvl, "enabled"); adaptive = nvlist_get_bool(nvl, "adaptive"); @@ -1485,9 +1491,9 @@ pfctl_get_syncookies(int dev, struct pfctl_syncookies *s) s->lowwater = nvlist_get_number(nvl, "lowwater") * 100 / state_limit; s->halfopen_states = nvlist_get_number(nvl, "halfopen_states"); +out: nvlist_destroy(nvl); - - return (0); + return (ret); } int