From 4b35ef60ac062df9c47bc00b92558cd5fe5a26a9 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Fri, 11 Mar 2022 22:19:40 -0800 Subject: [PATCH] os_get_passwd: Fix potential omission of gid/uid values in non-Windows 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 #589, and a follow up to #590. --- src/misc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/misc.c b/src/misc.c index 9d95dc4a..26be960f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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");