Skip to content

Commit 62044a5

Browse files
feat: gracefully handle command not found exception - avoid creds exposure (#54406)
* gracefully handle command not found exception to avoid exposure of credentials * Update DbCommand.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 01571b3 commit 62044a5

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/Illuminate/Database/Console/DbCommand.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Support\ConfigurationUrlParser;
77
use Symfony\Component\Console\Attribute\AsCommand;
8+
use Symfony\Component\Process\Exception\ProcessFailedException;
89
use Symfony\Component\Process\Process;
910
use UnexpectedValueException;
1011

@@ -44,13 +45,21 @@ public function handle()
4445
return Command::FAILURE;
4546
}
4647

47-
(new Process(
48-
array_merge([$this->getCommand($connection)], $this->commandArguments($connection)),
49-
null,
50-
$this->commandEnvironment($connection)
51-
))->setTimeout(null)->setTty(true)->mustRun(function ($type, $buffer) {
52-
$this->output->write($buffer);
53-
});
48+
try {
49+
(new Process(
50+
array_merge([$command = $this->getCommand($connection)], $this->commandArguments($connection)),
51+
null,
52+
$this->commandEnvironment($connection)
53+
))->setTimeout(null)->setTty(true)->mustRun(function ($type, $buffer) {
54+
$this->output->write($buffer);
55+
});
56+
} catch (ProcessFailedException $e) {
57+
throw_unless($e->getProcess()->getExitCode() === 127, $e);
58+
59+
$this->error("{$command} not found in path.");
60+
61+
return Command::FAILURE;
62+
}
5463

5564
return 0;
5665
}

0 commit comments

Comments
 (0)