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_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=1754450730; bh=fPMjPdiZ5u/3PjWe/Wn+LfxcmvNim6ptQIo5sHrInug=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To: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=FMnubLXcIQW3/TgJVkQloPJ5espA3WLnIcuoTXXu2aX0hwHPS3nPZ7nAR6W1a2j5p H2okABcup0pYgo6/85FRwTBGTt1h57eLf2uJx5YNGYjZskK7JcGz3hfKusLRg3es+y XL8tFqQh5ZUpkC/jzgZQ2oN4dNAv/Uez/GWE2mhMUx3ZdisSHFnEMluPMICdFW9nyL h4dQfz0/jt+ElkCjhkNXDRVfICMsaCIS8oUsTZrfiSJE9NQNgclevqepJKsc5QhUoc y7crHBuIqdoFHUNoU7OzzLzfqg6YOQHeoyONn9SXo4+cZfOGz7lC3sGlr3OGcI11e6 Gh8pIYqyJWhXw== Received: from linux.gnuweeb.org (unknown [182.253.126.229]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id AD1B33127C38; Wed, 6 Aug 2025 03:25:29 +0000 (UTC) Date: Wed, 6 Aug 2025 10:25:26 +0700 From: Ammar Faizi To: Ahmad Gani Cc: Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: Re: [PATCH gwproxy v3 2/6] dnslookup: Add a new parameter default_port Message-ID: References: <20250805130451.146549-1-reyuki@gnuweeb.org> <20250805130451.146549-3-reyuki@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250805130451.146549-3-reyuki@gnuweeb.org> X-Machine-Hash: hUx9VaHkTWcLO7S8CQCslj6OzqBx2hfLChRz45nPESx5VSB/xuJQVOKOB1zSXE3yc9ntP27bV1M1 List-Id: 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