Skip to content

Commit 93f8fb1

Browse files
committed
uuid: Use posix_geteuid() if it exists, instead of getmyuid()
We're trying to construct a filename which will be writable by other requests that use the same filename. getmyuid() is not correct since it just gives the owner of the script being executed -- requests by different users will use the same name and thus will conflict with each other. posix_geteuid() is the UID used for permission checks when creating files, so it is the correct function to call in the hypothetical scenario where the real and effective UIDs differ. Bug: T358768 Change-Id: Idd85308e59fcd3a96ab8ba4cdb686f1affdf774c
1 parent c4e9ec2 commit 93f8fb1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

includes/libs/uuid/GlobalIdGenerator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ public function __construct( $tempDirectory, $shellCallback ) {
9797
throw new InvalidArgumentException( "No temp directory provided" );
9898
}
9999
$this->tmpDir = $tempDirectory;
100-
// Check if getmyuid exists, it could be disabled for security reasons - T324513
101-
$fileSuffix = function_exists( 'getmyuid' ) ? getmyuid() : '';
100+
// Include the UID in the filename (T268420, T358768)
101+
if ( function_exists( 'posix_geteuid' ) ) {
102+
$fileSuffix = posix_geteuid();
103+
} elseif ( function_exists( 'getmyuid' ) ) {
104+
$fileSuffix = getmyuid();
105+
} else {
106+
$fileSuffix = '';
107+
}
102108
$this->uniqueFilePrefix = self::FILE_PREFIX . $fileSuffix;
103109
$this->nodeIdFile = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-nodeid';
104110
// If different processes run as different users, they may have different temp dirs.

0 commit comments

Comments
 (0)