Skip to content

Commit

Permalink
os_get_passwd: Fix potential omission of gid/uid values in non-Window…
Browse files Browse the repository at this point in the history
…s environments

-1 only has special meaning on Windows, and gid and uid are always set to -1 on Windows, so we can just omit the gid and uid fields on Windows instead of checking for -1. This is a better fix for luvit#589, and a follow up to luvit#590.
  • Loading branch information
squeek502 committed Mar 12, 2022
1 parent 4e7e56c commit 4b35ef6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,15 @@ static int luv_os_get_passwd(lua_State* L) {
lua_pushstring(L, pwd.username);
lua_setfield(L, -2, "username");
}
if (pwd.uid != -1) {
lua_pushinteger(L, pwd.uid);
lua_setfield(L, -2, "uid");
}
if (pwd.gid != -1) {
lua_pushinteger(L, pwd.gid);
lua_setfield(L, -2, "gid");
}
// From the uv_os_get_passwd docs:
// "On Windows, uid and gid are set to -1 and have no meaning"
// so we omit these fields on Windows.
#ifndef _WIN32
lua_pushinteger(L, pwd.uid);
lua_setfield(L, -2, "uid");
lua_pushinteger(L, pwd.gid);
lua_setfield(L, -2, "gid");
#endif
if (pwd.shell) {
lua_pushstring(L, pwd.shell);
lua_setfield(L, -2, "shell");
Expand Down

0 comments on commit 4b35ef6

Please sign in to comment.