When dropping privileges, check return values.
setuid() and family can fail. Check return values to make sure this doesn't happen unexpectedly. Also call setgid() to drop root group permissions. Change-Id: Id06fbe6239e2ed2fe23368695e333514e0581e6d
This commit is contained in:
@ -218,8 +218,18 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
/* switch to non-root user and group */
|
/* switch to non-root user and group */
|
||||||
gid_t groups[] = { AID_LOG, AID_SDCARD_RW, AID_MOUNT };
|
gid_t groups[] = { AID_LOG, AID_SDCARD_RW, AID_MOUNT };
|
||||||
setgroups(sizeof(groups)/sizeof(groups[0]), groups);
|
if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
|
||||||
setuid(AID_SHELL);
|
LOGE("Unable to setgroups, aborting: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (setgid(AID_SHELL) != 0) {
|
||||||
|
LOGE("Unable to setgid, aborting: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (setuid(AID_SHELL) != 0) {
|
||||||
|
LOGE("Unable to setuid, aborting: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
char path[PATH_MAX], tmp_path[PATH_MAX];
|
char path[PATH_MAX], tmp_path[PATH_MAX];
|
||||||
pid_t gzip_pid = -1;
|
pid_t gzip_pid = -1;
|
||||||
|
Reference in New Issue
Block a user