Skip to content

Fix #127: Linux unix:unix-getpwuid segfaults with invalid uid

Raymond Toy requested to merge issue-127-getpwuid-segfault into master

On Linux, unix:unix-getpwuid would segfault with an invalid uid. This was caused because we needed to check the return pwd structure arg instead of the function return value. The function return value indicates how getpwuid failed.

We also updated the function so that when it returns NIL (for failure), a second return value is provided which is the return value of the function indicating the failure mode.

Also, the size of the buf passed to getpwuid_r is increased in size from 1024 to 16384. This is based on the example in the Linux manpage that uses 16384 if sysconf fails. (We don't use sysconf here.)

Finally, add a test for this where we just start at uid 10000 and keep going until we find one that doesn't exist. This should not segfault.

Merge request reports