aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Prestwood <prestwoj@gmail.com>2020-04-02 09:48:48 -0700
committerDenis Kenzior <denkenz@gmail.com>2020-04-02 00:31:36 -0500
commit689a1ed8581f76b88c28ae0cd889b01e2623b290 (patch)
tree0841a2ad65ed6d0b2f673505b4d53f1a52730475
parent935138500f4868f6b556ae4e05dc9e4486bd3497 (diff)
downloadiwd-689a1ed8581f76b88c28ae0cd889b01e2623b290.tar.gz
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.
-rw-r--r--tools/test-runner.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/tools/test-runner.c b/tools/test-runner.c
index 54a3bbde9..44f08a0e7 100644
--- a/tools/test-runner.c
+++ b/tools/test-runner.c
@@ -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,