Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: address review 2
Signed-off-by: Simon L <[email protected]>
  • Loading branch information
szaimen committed May 24, 2024
commit 1afe55bd5f68205645d16a32b56cef2af4f3bb7f
3 changes: 2 additions & 1 deletion console.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ function exceptionHandler($exception) {

$user = posix_getuid();
$userNameArray = posix_getpwuid($user);
$username = null;
if ($userNameArray !== false) {
$userName = $userNameArray['name'];
}
$configUser = fileowner(OC::$configDir . 'config.php');
$configuredUser = $config->getSystemValueString('php.user', '');
if ($user !== $configUser && $userName !== $configuredUser) {
if ($user !== $configUser && $username !== null && $userName !== $configuredUser) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check always needs to check for $configuredUser if set. Also accepting $configUser can lead to the very issue this is trying to prevent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like

$phpUser = $config->getSystemValueString('php.user', '');
if (!$phpUser) {
    $userNameArray = posix_getpwuid($user);
	if ($userNameArray !== false) {
		$phpUser = $userNameArray['name'];
	}
}
if ($user != $phpUser) {

maybe

echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
echo "Current user id: " . $user . PHP_EOL;
echo "Owner id of config.php: " . $configUser . PHP_EOL;
Expand Down
5 changes: 3 additions & 2 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@

$user = posix_getuid();
$userNameArray = posix_getpwuid($user);
if ($userNameArray !== false)) {
$username = null;
if ($userNameArray !== false) {
$userName = $userNameArray['name'];
}
$configUser = fileowner(OC::$configDir . 'config.php');
$configuredUser = $config->getSystemValueString('php.user', '');
if ($user !== $configUser && $userName !== $configuredUser) {
if ($user !== $configUser && $username !== null && $userName !== $configuredUser) {

Check failure

Code scanning / Psalm

TypeDoesNotContainType

Type null for $username is always !null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is not true? How can I fix this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? Documentation says it should return false on failure: https://www.php.net/manual/en/function.posix-getpwuid.php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
echo "Current user id: " . $user . PHP_EOL;
echo "Owner id of config.php: " . $configUser . PHP_EOL;
Expand Down