Skip to content

Commit

Permalink
os_get_passwd: Explicitly compare uid/gid against -1 instead of >= 0 (#…
Browse files Browse the repository at this point in the history
…590)

In Libuv 1.44.0, uv_passwd_t.uid/gid was changed to be unsigned, so the >= 0 check would always return true. Changing to compare against -1 explicitly fixes #589 while still maintaining correct functionality when built against previous Libuv versions. Note that with Libuv 1.44.0 and above, this relies on implicitly casting -1 to unsigned long (the type of `uv_passwd_t.uid`/`uv_passwd_t.gid`).
  • Loading branch information
squeek502 authored Mar 12, 2022
1 parent c234b86 commit 4e7e56c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ static int luv_os_get_passwd(lua_State* L) {
lua_pushstring(L, pwd.username);
lua_setfield(L, -2, "username");
}
if (pwd.uid >= 0) {
if (pwd.uid != -1) {
lua_pushinteger(L, pwd.uid);
lua_setfield(L, -2, "uid");
}
if (pwd.gid >= 0) {
if (pwd.gid != -1) {
lua_pushinteger(L, pwd.gid);
lua_setfield(L, -2, "gid");
}
Expand Down

0 comments on commit 4e7e56c

Please sign in to comment.