Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20261118143423.GT5716@brightrain.aerifal.cx>
Date: Wed, 18 Nov 2026 09:34:24 -0500
From: Rich Felker <dalias@...c.org>
To: illiliti <ilt@...s.net>
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH v1 10/18] fts: drop aligned statp alloc support

On Wed, Nov 18, 2026 at 03:49:52PM +0300, illiliti wrote:
> ---
>  src/misc/fts.c | 34 +---------------------------------
>  1 file changed, 1 insertion(+), 33 deletions(-)
> 
> diff --git a/src/misc/fts.c b/src/misc/fts.c
> index bae0f8a9..498ef576 100644
> --- a/src/misc/fts.c
> +++ b/src/misc/fts.c
> @@ -53,12 +53,6 @@ static unsigned short fts_stat(FTS *, FTSENT *, int);
>  static int	 fts_safe_changedir(const FTS *, const FTSENT *, int,
>      const char *);
>  
> -#if defined(ALIGNBYTES) && defined(ALIGN)
> -#define	FTS_ALLOC_ALIGNED	1
> -#else
> -#undef	FTS_ALLOC_ALIGNED
> -#endif
> -
>  #ifndef ftsent_namelen_truncate
>  #define ftsent_namelen_truncate(a)	\
>      ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a))
> @@ -989,29 +983,7 @@ static FTSENT *
>  fts_alloc(FTS *sp, const char *name, size_t namelen)
>  {
>  	FTSENT *p;
> -#if defined(FTS_ALLOC_ALIGNED)
> -	size_t len;
> -#endif
> -
> -#if defined(FTS_ALLOC_ALIGNED)
> -	/*
> -	 * The file name is a variable length array and no stat structure is
> -	 * necessary if the user has set the nostat bit.  Allocate the FTSENT
> -	 * structure, the file name and the stat structure in one chunk, but
> -	 * be careful that the stat structure is reasonably aligned.  Since the
> -	 * fts_name field is declared to be of size 1, the fts_name pointer is
> -	 * namelen + 2 before the first possible address of the stat structure.
> -	 */

I've skimmed through this quickly to give some initial feedback, and
this is the first thing that really stuck out at me. The thing of
using a size-1 array as if it were a flexible array member produces
undefined behavior in the caller and is not acceptable in a public
interface or internal to musl. Hopefully this isn't something callers
can depend on and it can just be fixed to use a real FAM.

Overall I'm probably not going to get to an answer on this right away;
there's a lot more pressing stuff, and everything has gotten along
fine without fts in musl for the past 15 years.

Some things that would be helpful in evaluating both the code and
whether it makes sense to include would be:

- A squashed patch, and explanations of the motivations for individual
  changes like the one I'm replying to here for the broken-down
  changes. It's a lot more work to evaluate potentially-unacceptable
  parts of the patch when it's not apparent without reading all of the
  other patches whether those things will be removed by the end.

- Some research on what programs that use fts are doing now. Are they
  shipping their own drop-ins, or using a library? I don't think
  libbsd has it but I might be misremembering.

- Is the fts public interface actually common between implementations?
  Just now looking up the fts_name thing, it looks like glibc has
  fts_name as a pointer rather than an array. Generally musl is
  hesitant to take on interfaces that have multiple incompatible
  historical versions by the same name, since doing so prevents
  dropping in one to match what the caller expects and might conflict
  with future standardization, putting us in a bad position with
  regards to ABI.

Also, for future reference, it's nicer if you can send patch series as
multiple MIME attachments rather than a git-send-email style thread.
Less inbox clutter to list subscribers, and it would make it possible
to reply to multiple parts of the series in a single reply rather than
having replies attached just to one branch of the thread.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.