Skip to content

Commit 050a019

Browse files
committed
fix: consider open_basedir
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 53d60a6 commit 050a019

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/OperatingSystem.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ public function getLinuxDistribution(): string
7777
private function getFromEtcRelease(): string
7878
{
7979
$file = $this->rootFolder . '/etc/*-release';
80-
foreach (glob($file) as $path) {
80+
$filesFound = glob($file);
81+
if (!$filesFound) {
82+
return '';
83+
}
84+
foreach ($filesFound as $path) {
8185
$content = file_get_contents($path);
8286
preg_match('/^ID=(?<version>.*)$/m', $content, $matches);
8387
if (isset($matches['version'])) {
@@ -102,26 +106,36 @@ public function getFromLsbRelease(): string
102106

103107
private function isDebian(): string
104108
{
105-
if (file_exists($this->rootFolder . '/etc/debian_version')) {
106-
return 'Debian';
109+
if ($this->isInOpenBasedir($this->rootFolder . '/etc/debian_version')) {
110+
if (file_exists($this->rootFolder . '/etc/debian_version')) {
111+
return 'Debian';
112+
}
107113
}
108-
if (!$this->runSafe('type apt 2>/dev/null >/dev/null &')) {
114+
if (!$this->runSafe('type apt')) {
109115
return '';
110116
}
111117
return 'Debian';
112118
}
113119

114120
private function isAlpine(): string
115121
{
116-
if (!$this->runSafe('type apk 2>/dev/null >/dev/null &')) {
122+
if (!$this->runSafe('type apk')) {
117123
return '';
118124
}
119125
return 'Alpine';
120126
}
121127

122128
private function runSafe(string $command): string
123129
{
124-
$output = shell_exec($command . ' 2>/dev/null >/dev/null &');
130+
$output = shell_exec($command . ' 2>/dev/null');
125131
return (string) $output;
126132
}
133+
134+
private function isInOpenBasedir(string $path): bool {
135+
$openBasedir = ini_get('open_basedir');
136+
if (empty($openBasedir) || strpos($openBasedir, $path) !== false) {
137+
return true;
138+
}
139+
return false;
140+
}
127141
}

0 commit comments

Comments
 (0)