From: Ahmad Gani <reyuki@gnuweeb.org>
To: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Cc: Ahmad Gani <reyuki@gnuweeb.org>,
Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>
Subject: [PATCH gwproxy v0] net: Fix convert_str_to_ssaddr
Date: Sat, 16 Aug 2025 17:38:02 +0700 [thread overview]
Message-ID: <20250816103807.27781-1-reyuki@gnuweeb.org> (raw)
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 <reyuki@gnuweeb.org>
---
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 <arpa/inet.h>
+#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
next reply other threads:[~2025-08-16 10:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-16 10:38 Ahmad Gani [this message]
2025-08-16 15:28 ` [PATCH gwproxy v0] net: Fix convert_str_to_ssaddr Ammar Faizi
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=20250816103807.27781-1-reyuki@gnuweeb.org \
--to=reyuki@gnuweeb.org \
--cc=alviro.iskandar@gnuweeb.org \
--cc=ammarfaizi2@gnuweeb.org \
--cc=gwml@vger.gnuweeb.org \
/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