Copilot commented on code in PR #13686:
URL: https://github.com/apache/trafficserver/pull/13686#discussion_r4012276333


##########
src/api/InkAPITest.cc:
##########
@@ -2084,8 +2084,14 @@ REGRESSION_TEST(SDK_API_TSfopen)(RegressionTest *test, 
int /* atype ATS_UNUSED *
 
   // Create unique tmp _file_name_, do not use any TS file_name
   snprintf(write_file_name, PATH_NAME_MAX, "/tmp/%sXXXXXX", 
ts::filename::PLUGIN);
-  int write_file_fd; // this file will be reopened below
-  if ((write_file_fd = mkstemp(write_file_name)) <= 0) {
+
+  // Narrow the umask across mkstemp so the temporary file cannot land in /tmp
+  // group or world accessible, whatever the process umask happens to be.
+  const mode_t old_umask     = umask(S_IRWXG | S_IRWXO);
+  int          write_file_fd = mkstemp(write_file_name); // this file will be 
reopened below
+
+  umask(old_umask);

Review Comment:
   This changes the process-wide umask while `traffic_server` is still running. 
Another event thread can create a file during this window, and a concurrent 
umask change can make the restore write back a stale value; `mkstemp` already 
guarantees a 0600 file on POSIX, so the race-free fix is to remove this 
process-wide mutation (or use `fchmod` on the returned descriptor if an 
explicit mode is required).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to