Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
process: fix setuid() and setgid() error reporting
Browse files Browse the repository at this point in the history
Zero errno before calling getgrnam_r() or getpwnam_r(). If errno had previously
been clobbered, node would report the wrong error.
  • Loading branch information
bnoordhuis committed Sep 17, 2012
1 parent db5c26e commit 96ca59f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/node.cc
Expand Up @@ -1508,6 +1508,7 @@ static Handle<Value> SetGid(const Arguments& args) {
struct group grp, *grpp = NULL;
int err;

errno = 0;
if ((err = getgrnam_r(*grpnam, &grp, getbuf, ARRAY_SIZE(getbuf), &grpp)) ||
grpp == NULL) {
if (errno == 0)
Expand Down Expand Up @@ -1548,6 +1549,7 @@ static Handle<Value> SetUid(const Arguments& args) {
struct passwd pwd, *pwdp = NULL;
int err;

errno = 0;
if ((err = getpwnam_r(*pwnam, &pwd, getbuf, ARRAY_SIZE(getbuf), &pwdp)) ||
pwdp == NULL) {
if (errno == 0)
Expand Down

0 comments on commit 96ca59f

Please sign in to comment.