abuild-sudo: handle errors from setuid/setgid

ref https://gitlab.alpinelinux.org/alpine/abuild/-/issues/10102
This commit is contained in:
Natanael Copa 2023-10-17 18:25:04 +02:00
parent 1332d5b171
commit fcdfd871af
1 changed files with 4 additions and 2 deletions

View File

@ -125,9 +125,11 @@ int main(int argc, const char *argv[])
argv[0] = path;
/* set our uid to root so bbsuid --install works */
setuid(0);
if (setuid(0) < 0)
err(1, "setuid(0) failed");
/* set our gid to root so apk commit hooks run with the same gid as for "sudo apk add ..." */
setgid(0);
if (setgid(0) < 0)
err(1, "setgid(0) failed");
execv(path, (char * const*)argv);
perror(path);
return 1;