netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antonio Quartulli <antonio@openvpn.net>
To: netdev@vger.kernel.org
Cc: Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Sabrina Dubroca <sd@queasysnail.net>,
	Antonio Quartulli <antonio@openvpn.net>
Subject: [PATCH net-next 05/10] selftest/net/ovpn: fix crash in case of getaddrinfo() failure
Date: Fri,  9 May 2025 16:26:15 +0200	[thread overview]
Message-ID: <20250509142630.6947-6-antonio@openvpn.net> (raw)
In-Reply-To: <20250509142630.6947-1-antonio@openvpn.net>

getaddrinfo() may fail with error code different from EAI_FAIL
or EAI_NONAME, however in this case we still try to free the
results object, thus leading to a crash.

Fix this by bailing out on any possible error.

Fixes: 959bc330a439 ("testing/selftests: add test tool and scripts for ovpn module")
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
---
 tools/testing/selftests/net/ovpn/ovpn-cli.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/ovpn/ovpn-cli.c b/tools/testing/selftests/net/ovpn/ovpn-cli.c
index 69e41fc07fbc..c6372a1b4728 100644
--- a/tools/testing/selftests/net/ovpn/ovpn-cli.c
+++ b/tools/testing/selftests/net/ovpn/ovpn-cli.c
@@ -1753,8 +1753,11 @@ static int ovpn_parse_remote(struct ovpn_ctx *ovpn, const char *host,
 
 	if (host) {
 		ret = getaddrinfo(host, service, &hints, &result);
-		if (ret == EAI_NONAME || ret == EAI_FAIL)
+		if (ret) {
+			fprintf(stderr, "getaddrinfo on remote error: %s\n",
+				gai_strerror(ret));
 			return -1;
+		}
 
 		if (!(result->ai_family == AF_INET &&
 		      result->ai_addrlen == sizeof(struct sockaddr_in)) &&
@@ -1769,8 +1772,11 @@ static int ovpn_parse_remote(struct ovpn_ctx *ovpn, const char *host,
 
 	if (vpnip) {
 		ret = getaddrinfo(vpnip, NULL, &hints, &result);
-		if (ret == EAI_NONAME || ret == EAI_FAIL)
+		if (ret) {
+			fprintf(stderr, "getaddrinfo on vpnip error: %s\n",
+				gai_strerror(ret));
 			return -1;
+		}
 
 		if (!(result->ai_family == AF_INET &&
 		      result->ai_addrlen == sizeof(struct sockaddr_in)) &&
-- 
2.49.0


  parent reply	other threads:[~2025-05-09 14:27 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-09 14:26 [PATCH net-next 00/10] pull request for net-next: ovpn 2025-05-09 Antonio Quartulli
2025-05-09 14:26 ` [PATCH net-next 01/10] MAINTAINERS: add Sabrina as official reviewer for ovpn Antonio Quartulli
2025-05-09 14:34   ` Andrew Lunn
2025-05-12  8:22     ` Antonio Quartulli
2025-05-13  1:17       ` Jakub Kicinski
2025-05-09 14:26 ` [PATCH net-next 02/10] MAINTAINERS: update git URL " Antonio Quartulli
2025-05-09 14:26 ` [PATCH net-next 03/10] ovpn: set skb->ignore_df = 1 before sending IPv6 packets out Antonio Quartulli
2025-05-13  7:37   ` Paolo Abeni
2025-05-13  7:49     ` Gert Doering
2025-05-13  7:51     ` Antonio Quartulli
2025-05-13  8:51       ` Paolo Abeni
2025-05-13  9:01         ` Antonio Quartulli
2025-05-09 14:26 ` [PATCH net-next 04/10] ovpn: don't drop skb's dst when xmitting packet Antonio Quartulli
2025-05-13  7:45   ` Paolo Abeni
2025-05-13  7:54     ` Antonio Quartulli
2025-05-09 14:26 ` Antonio Quartulli [this message]
2025-05-13  7:48   ` [PATCH net-next 05/10] selftest/net/ovpn: fix crash in case of getaddrinfo() failure Paolo Abeni
2025-05-13  8:02     ` Antonio Quartulli
2025-05-09 14:26 ` [PATCH net-next 06/10] ovpn: fix ndo_start_xmit return value on error Antonio Quartulli
2025-05-09 14:26 ` [PATCH net-next 07/10] selftest/net/ovpn: extend coverage with more test cases Antonio Quartulli
2025-05-09 14:26 ` [PATCH net-next 08/10] ovpn: drop useless reg_state check in keepalive worker Antonio Quartulli
2025-05-09 14:26 ` [PATCH net-next 09/10] ovpn: improve 'no route to host' debug message Antonio Quartulli
2025-05-13  7:53   ` Paolo Abeni
2025-05-13  8:04     ` Antonio Quartulli
2025-05-09 14:26 ` [PATCH net-next 10/10] ovpn: ensure sk is still valid during cleanup Antonio Quartulli
2025-05-13  1:37   ` Jakub Kicinski
2025-05-13  8:21     ` Paolo Abeni
2025-05-13  9:19       ` Antonio Quartulli
2025-05-13 14:55         ` Antonio Quartulli
2025-05-09 14:40 ` [PATCH net-next 00/10] pull request for net-next: ovpn 2025-05-09 Andrew Lunn
2025-05-09 14:55   ` Antonio Quartulli
  -- strict thread matches above, loose matches on Subject: below --
2025-05-15 11:13 [PATCH net-next 00/10] ovpn: pull request for net-next: ovpn 2025-05-15 Antonio Quartulli
2025-05-15 11:13 ` [PATCH net-next 05/10] selftest/net/ovpn: fix crash in case of getaddrinfo() failure Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250509142630.6947-6-antonio@openvpn.net \
    --to=antonio@openvpn.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).