Skip to content

Commit

Permalink
Fixed handling of getenv results in test_cli_logname (as described in #…
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Dec 6, 2023
1 parent fbe8497 commit 4707647
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/tests/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,13 @@ TEST_F(rnp_tests, test_cli_dump)

TEST_F(rnp_tests, test_cli_logname)
{
// getenv function is not required to be thread-safe.
// Another call to getenv, as well as a call to the POSIX functions setenv(), unsetenv(),
// and putenv() may invalidate the pointer returned by a previous call or modify the string
// obtained from a previous call.
char * logname = getenv("LOGNAME");
std::string saved_logname(logname ? logname : "");

char * user = getenv("USER");
std::string testname(user ? user : "user");
testname.append("-test-user");
Expand All @@ -851,7 +857,7 @@ TEST_F(rnp_tests, test_cli_logname)
}

if (logname) {
setenv("LOGNAME", logname, 1);
setenv("LOGNAME", saved_logname.c_str(), 1);
} else {
unsetenv("LOGNAME");
}
Expand Down

0 comments on commit 4707647

Please sign in to comment.