3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

test-runner: fix segfault running with --log non-root

When running test-runner as non-root the environment variables
SUDO_GID/SUDO_UID were unset, causing atoi to segfault. This replaces
atoi with strtol, and checks the existance of SUDO_GID/SUDO_UID
before trying to turn it into an integer. This patch also allows
the uid/gid to be read from the user if running as non-root.

Note: running as non-root does require the users permissions to be
setup properly. Directories and files are created when running with
logging, so if the user running test-runner does not have these
permissions the creation of these files will fail.
This commit is contained in:
James Prestwood 2020-04-02 09:48:48 -07:00 committed by Denis Kenzior
parent 935138500f
commit 689a1ed858

View File

@ -3093,6 +3093,8 @@ int main(int argc, char *argv[])
uint8_t actions = 0;
struct tm *timeinfo;
time_t t;
char *gid;
char *uid;
l_log_set_stderr();
@ -3193,8 +3195,16 @@ int main(int argc, char *argv[])
time(&t);
timeinfo = localtime(&t);
log_gid = atoi(getenv("SUDO_GID"));
log_uid = atoi(getenv("SUDO_UID"));
gid = getenv("SUDO_GID");
uid = getenv("SUDO_UID");
if (!gid || !uid) {
log_gid = getgid();
log_uid = getuid();
} else {
log_gid = strtol(gid, NULL, 10);
log_uid = strtol(uid, NULL, 10);
}
snprintf(log_dir, sizeof(log_dir), "%s/run-%d-%d-%d-%d",
optarg, timeinfo->tm_year + 1900,