landley / toybox

toybox
http://landley.net/toybox
BSD Zero Clause License
2.44k stars 340 forks source link

cp: should filter mode bits on newly created object #530

Open jtyler76 opened 4 days ago

jtyler76 commented 4 days ago

In cp, the newly created object (the copy) is created using the mode bits of the source object (https://github.com/landley/toybox/blob/fb3ca98e2faaa11512061cdd3fc946ddf0c2696b/toys/posix/cp.c#L296). The issue is that the mode of the source object may have bits set that are not file permission bits, and POSIX states that the effect of setting such bits in open()/openat() is unspecified (see the POSIX spec page for open()/openat() when it describes O_CREAT).

The mode bits passed to openat() in the aforementioned line should be filtered down to only the file permission bits as listed on the <sys/stat.h> page of the POSIX spec.

landley commented 2 days ago

On 11/25/24 14:09, jtyler76 wrote:

The mode bits passed to openat() in the aforementioned line should be filtered down to only the file permission bits as listed on the <sys/stat.h> page of the POSIX spec.

What use case broke on which system?