U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@mailbox.org>
To: Quentin Schulz <quentin.schulz@cherry.de>,
	Aristo Chen <aristo.chen@canonical.com>,
	u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>,
	Marek Vasut <marek.vasut+renesas@mailbox.org>,
	Rasmus Villemoes <ravi@prevas.dk>, Simon Glass <sjg@chromium.org>
Subject: Re: [PATCH v1 1/2] tools: mkimage: fix get_basename crash on paths with dotted directories
Date: Thu, 21 May 2026 18:17:05 +0200	[thread overview]
Message-ID: <57eda5e0-e82d-43a0-af31-bf2db62eae56@mailbox.org> (raw)
In-Reply-To: <b1206a04-9800-4323-bf4a-cb8a14f15f8c@cherry.de>

On 5/21/26 6:12 PM, Quentin Schulz wrote:

Hello Quentin,

>>> +    p = strrchr(start, '.');
>>> +    end = p ? p : start + strlen(start);
>>>       len = end - start;
>>>       if (len >= size)
>>>           len = size - 1;
>>
>> Why not call basename(3) directly in here ? Why reimplement it ?
> 
> """
> Warning: there are two different functions basename() - see below.
> 
> [...]
> 
> Notes
> 
> There are two different versions of basename() - the POSIX version 
> described above, and the GNU version, which one gets after
> 
>      #define _GNU_SOURCE         /* See feature_test_macros(7) */
>      #include <string.h>
> 
> The GNU version never modifies its argument, and returns the empty 
> string when path has a trailing slash, and in particular also when it is 
> "/". There is no GNU version of dirname().
> 
> With glibc, one gets the POSIX version of basename() when <libgen.h> is 
> included, and the GNU version otherwise.
> 
> Bugs
> 
> In the glibc implementation of the POSIX versions of these functions 
> they modify their argument, and segfault when called with a static 
> string like "/usr/". Before glibc 2.2.1, the glibc version of dirname() 
> did not correctly handle pathnames with trailing '/' characters, and 
> generated a segfault if given a NULL argument.
> """
> 
> Not very reassuring, tbh.

Writing our own variant with its own set of bugs is worse than using a 
common implementation which has the bugs removed over time due to effort 
of the various users.

If basename(3) is not an option, is there another common alternative ?

  reply	other threads:[~2026-05-21 16:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21  2:34 [PATCH v1 1/2] tools: mkimage: fix get_basename crash on paths with dotted directories Aristo Chen
2026-05-21  2:35 ` [PATCH v1 2/2] test/py: cover " Aristo Chen
2026-05-21  9:10   ` Quentin Schulz
2026-05-21 15:59     ` Aristo Chen
2026-05-21  9:12 ` [PATCH v1 1/2] tools: mkimage: fix " Quentin Schulz
2026-05-21 16:09 ` Marek Vasut
2026-05-21 16:12   ` Quentin Schulz
2026-05-21 16:17     ` Marek Vasut [this message]
2026-05-22  3:07       ` Aristo Chen
2026-05-26  7:03 ` [PATCH v2 0/2] " Aristo Chen
2026-05-26  7:03   ` [PATCH v2 1/2] " Aristo Chen
2026-05-26  7:03   ` [PATCH v2 2/2] test/py: cover " Aristo Chen
2026-06-12  1:59   ` [PATCH v2 0/2] tools: mkimage: fix " Tom Rini

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=57eda5e0-e82d-43a0-af31-bf2db62eae56@mailbox.org \
    --to=marek.vasut@mailbox.org \
    --cc=aristo.chen@canonical.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=quentin.schulz@cherry.de \
    --cc=ravi@prevas.dk \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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