mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Florian Ziesche <florian.ziesche@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] dynlink: fix get_lfs64() with posix_fallocate64
Date: Thu, 23 May 2024 16:28:03 -0400	[thread overview]
Message-ID: <20240523202803.GC10433@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAB_d6t5+Bi1XL7D+xxaYn7R86WYfrDgn-_Z5+gy9nP5zagJ87w@mail.gmail.com>

On Fri, May 10, 2024 at 06:01:58PM +0200, Florian Ziesche wrote:
> Hi,
> 
> this patch increases the buffer size by one in get_lfs64() so that it
> works with posix_fallocate64.
> "posix_fallocate64" is 17 characters long, so 16 is one too short.
> 
> Simplified example:
> before: https://compiler-explorer.com/z/4qcPhcaWr
> after: https://compiler-explorer.com/z/scGvhddKW
> 
> ---
> diff --git a/ldso/dynlink.c b/ldso/dynlink.c
> index 42687da2..8707ae1c 100644
> --- a/ldso/dynlink.c
> +++ b/ldso/dynlink.c
> @@ -363,7 +363,7 @@ static struct symdef get_lfs64(const char *name)
>          "stat\0statfs\0statvfs\0tmpfile\0truncate\0versionsort\0"
>          "__fxstat\0__fxstatat\0__lxstat\0__xstat\0";
>      size_t l;
> -    char buf[16];
> +    char buf[17];
>      for (l=0; name[l]; l++) {
>          if (l >= sizeof buf) goto nomatch;
>          buf[l] = name[l];

Thanks for catching this. I questioned whether the 17 is sufficient,
but indeed the buffer is never nul terminated except when removing the
64, so it should be ok.

I think I'll apply your patch as a direct fix, but the whole copying
operation is unnecessary and I'll probably remove it. It works just as
well to strncmp and pass p instead of buf to find_sym, so that a
mutable copy of the name to lookup is never needed.

Rich

  reply	other threads:[~2024-05-23 20:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-10 16:01 Florian Ziesche
2024-05-23 20:28 ` Rich Felker [this message]
2024-06-22  1:06   ` Rich Felker
2024-06-22 18:37     ` Florian Ziesche

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=20240523202803.GC10433@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=florian.ziesche@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).