From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server-vie001.gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_DBL_BLOCKED_OPENDNS, URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=new2025; t=1755340714; bh=+HKWSyoqbCwOTns+mKvcN4urSOD1LTkFkuuibv1EMoI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:Date:From:Reply-To:Subject:To: Cc:In-Reply-To:References:Resent-Date:Resent-From:Resent-To: Resent-Cc:User-Agent:Content-Type:Content-Transfer-Encoding; b=fEnhV/tOcnx4Y8lVCwyljv9+phoBQvPHTWi4a6vr5X7KBlzSv9/AWRQbWXs9phW3h fxQvfsDruiZcawBmdiXZfmzDuAK9zxnecNoACmnQQjOw54KChy5+3qV7A443GzsrMF Jnj/Fqd7ftEkv+jh4mtb1F2m8Mal4ajr15RQIubP+2BeIb0wrWIMr0sm+WMq1ehdgR osI9njOUCLXN5TliG/yDN+rpt0op7JKyeNs7MeUt7Rs/ZaQh6g3flZYBS6U/vNDBn4 Rxry7tZwKLNGlsEAFP19JE6y4a2rJby015PP+q+VBWYqoz574E/UUEghEBbXycexle EA2GrRc/13q4g== Received: from zero (unknown [182.253.228.107]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 1CF69312801D; Sat, 16 Aug 2025 10:38:32 +0000 (UTC) From: Ahmad Gani To: Ammar Faizi Cc: Ahmad Gani , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH gwproxy v0] net: Fix convert_str_to_ssaddr Date: Sat, 16 Aug 2025 17:38:02 +0700 Message-ID: <20250816103807.27781-1-reyuki@gnuweeb.org> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: The function returns EINVAL if the string contains both an address and a port, but also specifies a non-zero default port. This behavior is incorrect— if the string already includes a port, the default port should be ignored. The default port should only serve as a fallback when no port is specified in the string. And add header guard in net.h Fixes e6bd4242be57 ("dnslookup: Add a new parameter default_port") Signed-off-by: Ahmad Gani --- src/gwproxy/net.c | 16 ++++++++-------- src/gwproxy/net.h | 5 +++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/gwproxy/net.c b/src/gwproxy/net.c index 221a636dab08..de70a8fd52ed 100644 --- a/src/gwproxy/net.c +++ b/src/gwproxy/net.c @@ -32,16 +32,16 @@ int convert_str_to_ssaddr(const char *str, return -EINVAL; l = p - str; p++; - if (*p != ':' && !default_port) - return -EINVAL; - } else if (!default_port) { + } else { p = strchr(str, ':'); - if (!p) - return -EINVAL; l = p - str; - } else { - l = strlen(str); - p = NULL; + } + + if (!p || *p != ':') { + if (default_port) + l = strlen(str); + else + return -EINVAL; } if (l >= sizeof(host)) diff --git a/src/gwproxy/net.h b/src/gwproxy/net.h index ff4ca1fc1965..85eac22a0266 100644 --- a/src/gwproxy/net.h +++ b/src/gwproxy/net.h @@ -4,6 +4,9 @@ #include +#ifndef GWP_NET_H +#define GWP_NET_H + #define FULL_ADDRSTRLEN (INET6_ADDRSTRLEN + sizeof(":65535[]") - 1) struct gwp_sockaddr { @@ -34,3 +37,5 @@ int convert_str_to_ssaddr(const char *str, */ int convert_ssaddr_to_str(char buf[FULL_ADDRSTRLEN], const struct gwp_sockaddr *gs); + +#endif /* #ifndef GWP_NET_H */ \ No newline at end of file -- Ahmad Gani