sudo-project / sudo

Utility to execute a command as another user
https://www.sudo.ws
Other
1.16k stars 208 forks source link

Fixed signedness issues when dealing with gid_t types #282

Closed RSilicon closed 1 year ago

RSilicon commented 1 year ago

gid and uid are unsigned on most platforms, and mode_t, being unsigned short but also passed as an int to some functions, are best passed cast to an integer.

millert commented 1 year ago

The use of int here is intentional. The problem with printing uid/gid as unsigned is that it ends up printing -1 as a large unsigned value which is not very useful. In system calls, a -1 value is used to indicate "no change" and it is helpful to preserve that in the debug output.

RSilicon commented 1 year ago

It gets printed as -1, I made sure of that, but yeah I can see why this would be a problem.

millert commented 1 year ago

Printing (unsigned int)-1 with the %u printf format will display 4294967295, not -1.