test-runner: fix segfault running with --log non-root
PATCH 1/1 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.
--- tools/test-runner.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
tools/test-runner.c +12 -2
@@ -3095,6 +3095,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 ();
@@ -3195,8 +3197,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,
Signature · 1 line
2.21.1
Denis Kenzior
AppliedHi James,
Quoted 6 lines · James Prestwood
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.
Quoted 8 lines
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.
--- tools/test-runner.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
Applied, thanks.
Regards,
-Denis