From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
To: Ahmad Gani <reyuki@gnuweeb.org>
Cc: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>
Subject: Re: [PATCH gwproxy v3 2/6] dnslookup: Add a new parameter default_port
Date: Wed, 6 Aug 2025 10:25:26 +0700 [thread overview]
Message-ID: <aJLLJimyitNFFbbb@linux.gnuweeb.org> (raw)
In-Reply-To: <20250805130451.146549-3-reyuki@gnuweeb.org>
On Tue, Aug 05, 2025 at 08:04:44PM +0700, Ahmad Gani wrote:
> __cold
> -int convert_str_to_ssaddr(const char *str, struct gwp_sockaddr *gs)
> +int convert_str_to_ssaddr(const char *str,
> + struct gwp_sockaddr *gs, uint16_t default_port)
> {
> static const struct addrinfo hints = {
> .ai_family = AF_UNSPEC,
> @@ -22,29 +23,34 @@ int convert_str_to_ssaddr(const char *str, struct gwp_sockaddr *gs)
> size_t l;
> int r;
>
> + l = strlen(str);
> + p = NULL;
I think this strlen() work can be placed in an else statement because
if you end up entering the 'if' or 'else-if' statements, the `l` var
will be overwritten anyway.
> if (*str == '[') {
> p = strchr(++str, ']');
> if (!p)
> return -EINVAL;
> l = p - str;
> - if (l >= sizeof(host))
> - return -EINVAL;
> p++;
> - if (*p != ':')
> + if (*p != ':' && !default_port)
> return -EINVAL;
> - } else {
> + } else if (!default_port) {
> p = strchr(str, ':');
> if (!p)
> return -EINVAL;
> l = p - str;
> - if (l >= sizeof(host))
> - return -EINVAL;
> }
^^^ Here.
>
> + if (l >= sizeof(host))
> + return -EINVAL;
> +
> strncpy(host, str, l);
> host[l] = '\0';
> - strncpy(port, p + 1, sizeof(port) - 1);
> - port[sizeof(port) - 1] = '\0';
> + if (default_port) {
> + snprintf(port, 6, "%u", default_port);
Use %hu for u16.
--
Ammar Faizi
next prev parent reply other threads:[~2025-08-06 3:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-05 13:04 [PATCH gwproxy v3 0/6] Initial work for DNS lookup implementation Ahmad Gani
2025-08-05 13:04 ` [PATCH gwproxy v3 1/6] dnslookup: Split common functionality and struct into net.h and net.c Ahmad Gani
2025-08-05 13:04 ` [PATCH gwproxy v3 2/6] dnslookup: Add a new parameter default_port Ahmad Gani
2025-08-06 3:25 ` Ammar Faizi [this message]
2025-08-05 13:04 ` [PATCH gwproxy v3 3/6] dnslookup: Allow only port string number Ahmad Gani
2025-08-05 13:04 ` [PATCH gwproxy v3 4/6] dnslookup: Initial work for implementation of C-ares-like getaddrinfo function Ahmad Gani
2025-08-05 13:04 ` [PATCH gwproxy v3 5/6] dnsparser: Transaction id creation is delegated to caller Ahmad Gani
2025-08-05 13:04 ` [PATCH gwproxy v3 6/6] dnslookup: Make gw_ares_getaddrinfo asynchronous Ahmad Gani
2025-08-06 3:31 ` [PATCH gwproxy v3 0/6] Initial work for DNS lookup implementation Ammar Faizi
2025-08-06 3:43 ` Ahmad Gani
-- strict thread matches above, loose matches on Subject: below --
2025-08-05 12:40 Ahmad Gani
2025-08-05 12:40 ` [PATCH gwproxy v3 2/6] dnslookup: Add a new parameter default_port Ahmad Gani
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=aJLLJimyitNFFbbb@linux.gnuweeb.org \
--to=ammarfaizi2@gnuweeb.org \
--cc=alviro.iskandar@gnuweeb.org \
--cc=gwml@vger.gnuweeb.org \
--cc=reyuki@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