Control: tags -1 + patch

Hi Guillem,

On Tue, Aug 27, 2024 at 12:48:17AM +0200, Guillem Jover wrote:
> As mentioned on IRC at the time, this change is not safe, because on
> GNU systems, the basename() implementation _and_ semantics change
> depending on the header (and feature macro) used. So this could make
> the code misbehave.

I concur. The patch changes behaviour.

> I guess the options are to check whether all call sites are safe with
> the POSIX basename() (which might depend on externally supplied input,
> and that would immediately make it unsuitable), or probably better to
> implement a local GNU compatible basename() to use if the system libc
> is missing it.

This is tools/attr.c. It has a main function and thus is an entry point
for an actual program. The basename function happens to be used exactly
once inside that main function and its argument is argv[0]. That happens
to be modifiable memory and hence the use of basename is safe in this
one situation. It may change the process name as it appears to other
processes though.

I note that Yocto, OpenWRT and OpenEmbedded opted for the same solution:
https://patchwork.yoctoproject.org/project/oe-core/patch/20231210202549.155550-6-raj.k...@gmail.com/
https://github.com/openwrt/packages/pull/24136
https://lists.openembedded.org/g/openembedded-core/topic/patch_6_6_attr_fix_build/103096128?p=,,,20,0,0,0::recentpostdate/sticky,,,20,0,160,103096128,previd%3D1702262795607091922,nextid%3D1702214323745660221&previd=1702262795607091922&nextid=1702214323745660221

If you still prefer a non-POSIX one, I suggest that you look at OpenBMC.
https://gerrit.openbmc.org/c/openbmc/openbmc/+/70802/1/meta-openembedded/meta-filesystems/recipes-support/composefs/files/0001-musl-basename-use-portable-implementation-for-basena.patch

Generally though, I prefer that we do not patch this in every distro
individually but upstream once even if we take longer to get there.

Helmut

Reply via email to