mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: Maks Mishin <maks.mishinfz@gmail.com>
Cc: musl@lists.openwall.com
Subject: [musl] Re: [PATCH] lookup_name: Replace call of vulnerable function
Date: Sun, 24 Mar 2024 13:52:23 -0400	[thread overview]
Message-ID: <20240324175222.GD32430@brightrain.aerifal.cx> (raw)
In-Reply-To: <20240324173251.31346-1-maks.mishinFZ@gmail.com>

On Sun, Mar 24, 2024 at 08:32:51PM +0300, Maks Mishin wrote:
> Use of vulnerable function 'strcpy' at lookup_name.c:122.
> This function is unsafe, use 'strncpy' instead.
> 
> Found by RASU JSC.
> 
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> ---
>  src/network/lookup_name.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c
> index 35218185..b59ec7c6 100644
> --- a/src/network/lookup_name.c
> +++ b/src/network/lookup_name.c
> @@ -119,7 +119,7 @@ static int dns_parse_callback(void *c, int rr, const void *data, int len, const
>  	if (rr == RR_CNAME) {
>  		if (__dn_expand(packet, (const unsigned char *)packet + plen,
>  		    data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp))
> -			strcpy(ctx->canon, tmp);
> +			strncpy(ctx->canon, tmp, sizeof ctx->canon);
>  		return 0;
>  	}
>  	if (ctx->cnt >= MAXADDRS) return 0;
> -- 
> 2.30.2

The buffer is explicitly chosen with size such that any hostname fits,
and the is_valid_hostname predicate checks this.

This RASU JSC static analysis tool you're using seems particularly bad
at its job.

           reply	other threads:[~2024-03-24 17:52 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20240324173251.31346-1-maks.mishinFZ@gmail.com>]

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=20240324175222.GD32430@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=maks.mishinfz@gmail.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).