* [PATCH gwproxy v0] net: Fix convert_str_to_ssaddr
@ 2025-08-16 10:38 Ahmad Gani
2025-08-16 15:28 ` Ammar Faizi
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Gani @ 2025-08-16 10:38 UTC (permalink / raw)
To: Ammar Faizi; +Cc: Ahmad Gani, Alviro Iskandar Setiawan, GNU/Weeb Mailing List
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH gwproxy v0] net: Fix convert_str_to_ssaddr
2025-08-16 10:38 [PATCH gwproxy v0] net: Fix convert_str_to_ssaddr Ahmad Gani
@ 2025-08-16 15:28 ` Ammar Faizi
0 siblings, 0 replies; 2+ messages in thread
From: Ammar Faizi @ 2025-08-16 15:28 UTC (permalink / raw)
To: Ahmad Gani; +Cc: Ammar Faizi, GNU/Weeb Mailing List, Alviro Iskandar Setiawan
On Sat, 16 Aug 2025 17:38:02 +0700, Ahmad Gani wrote:
> 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
>
> [...]
Applied, thanks!
[1/1] net: Fix convert_str_to_ssaddr
commit: 6c892ff947d8aba9c44055bfc605cc03087c3cee
Best regards,
--
Ammar Faizi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-16 15:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-16 10:38 [PATCH gwproxy v0] net: Fix convert_str_to_ssaddr Ahmad Gani
2025-08-16 15:28 ` Ammar Faizi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox