Hi, I noticed some really strange permissions on my history file of '-rw---S--T' and believe that the fix in commit 8e09e9293d666741e79bb5ecb9942ca4e652944e is incorrect.
The permissions passed to open() directly apply to the file, and as such passing ~(S_IXUSR | S_IRWXG | S_IRWXO) which is the negation of all the permissions you don't want, sure turns those off, but also flips all other bits to 1, which results in the observed broken behavior. man open(2) says "According to POSIX, the effect when other bits are set in mode is unspecified. On Linux, the following bits are also honored in mode: S_ISUID, S_ISGID, S_ISVTX". Unspecified is bad, and on Linux it turns on the set-uid/set-gid and sticky bits, which is not what you want at all.
Just passing (S_IRUSR | S_IWUSR) is all you need for open(), that way only the two permissions you do really want (user read and write) are turned on, the rest remains off.
Hi, I noticed some really strange permissions on my history file of '-rw---S--T' and believe that the fix in commit 8e09e9293d666741e79bb5ecb9942ca4e652944e is incorrect. The permissions passed to open() directly apply to the file, and as such passing ~(S_IXUSR | S_IRWXG | S_IRWXO) which is the negation of all the permissions you don't want, sure turns those off, but also flips all other bits to 1, which results in the observed broken behavior. man open(2) says "According to POSIX, the effect when other bits are set in mode is unspecified. On Linux, the following bits are also honored in mode: S_ISUID, S_ISGID, S_ISVTX". Unspecified is bad, and on Linux it turns on the set-uid/set-gid and sticky bits, which is not what you want at all. Just passing (S_IRUSR | S_IWUSR) is all you need for open(), that way only the two permissions you do really want (user read and write) are turned on, the rest remains off.