Skip to content

Commit 3332557

Browse files
committed
Fix return type hint and detect base64 decode crashes
1 parent b044109 commit 3332557

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

apache/helpers.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @param string $extension The file extension to use for the generated SSL files.
1313
* @return string A comma-separated list of paths to the generated SSL files.
1414
*/
15-
function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $extension): array {
15+
function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $extension): string {
1616
// Ensure the output directory exists
1717
if (!is_dir(PMA_SSL_DIR)) {
1818
mkdir(PMA_SSL_DIR, 0755, true);
@@ -26,13 +26,19 @@ function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $ex
2626
// Process each file
2727
foreach ($files as $file) {
2828
$output_file = PMA_SSL_DIR . "/pma-ssl-$prefix-$counter.$extension";
29-
29+
30+
$file_contents = base64_decode($file, true);
31+
if ($file_contents === false) {
32+
echo 'Failed to decode: ' . $file;
33+
exit(1);
34+
}
35+
3036
// Write the decoded file to the output directory
31-
if (file_put_contents($output_file, base64_decode($file)) === false) {
37+
if (file_put_contents($output_file, $file_contents) === false) {
3238
echo 'Failed to write to ' . $output_file;
3339
exit(1);
3440
}
35-
41+
3642
// Add the output file path to the list
3743
$ssl_files[] = $output_file;
3844
$counter++;

fpm-alpine/helpers.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @param string $extension The file extension to use for the generated SSL files.
1313
* @return string A comma-separated list of paths to the generated SSL files.
1414
*/
15-
function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $extension): array {
15+
function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $extension): string {
1616
// Ensure the output directory exists
1717
if (!is_dir(PMA_SSL_DIR)) {
1818
mkdir(PMA_SSL_DIR, 0755, true);
@@ -26,13 +26,19 @@ function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $ex
2626
// Process each file
2727
foreach ($files as $file) {
2828
$output_file = PMA_SSL_DIR . "/pma-ssl-$prefix-$counter.$extension";
29-
29+
30+
$file_contents = base64_decode($file, true);
31+
if ($file_contents === false) {
32+
echo 'Failed to decode: ' . $file;
33+
exit(1);
34+
}
35+
3036
// Write the decoded file to the output directory
31-
if (file_put_contents($output_file, base64_decode($file)) === false) {
37+
if (file_put_contents($output_file, $file_contents) === false) {
3238
echo 'Failed to write to ' . $output_file;
3339
exit(1);
3440
}
35-
41+
3642
// Add the output file path to the list
3743
$ssl_files[] = $output_file;
3844
$counter++;

fpm/helpers.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @param string $extension The file extension to use for the generated SSL files.
1313
* @return string A comma-separated list of paths to the generated SSL files.
1414
*/
15-
function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $extension): array {
15+
function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $extension): string {
1616
// Ensure the output directory exists
1717
if (!is_dir(PMA_SSL_DIR)) {
1818
mkdir(PMA_SSL_DIR, 0755, true);
@@ -26,13 +26,19 @@ function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $ex
2626
// Process each file
2727
foreach ($files as $file) {
2828
$output_file = PMA_SSL_DIR . "/pma-ssl-$prefix-$counter.$extension";
29-
29+
30+
$file_contents = base64_decode($file, true);
31+
if ($file_contents === false) {
32+
echo 'Failed to decode: ' . $file;
33+
exit(1);
34+
}
35+
3036
// Write the decoded file to the output directory
31-
if (file_put_contents($output_file, base64_decode($file)) === false) {
37+
if (file_put_contents($output_file, $file_contents) === false) {
3238
echo 'Failed to write to ' . $output_file;
3339
exit(1);
3440
}
35-
41+
3642
// Add the output file path to the list
3743
$ssl_files[] = $output_file;
3844
$counter++;

helpers.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @param string $extension The file extension to use for the generated SSL files.
1313
* @return string A comma-separated list of paths to the generated SSL files.
1414
*/
15-
function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $extension): array {
15+
function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $extension): string {
1616
// Ensure the output directory exists
1717
if (!is_dir(PMA_SSL_DIR)) {
1818
mkdir(PMA_SSL_DIR, 0755, true);
@@ -26,13 +26,19 @@ function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $ex
2626
// Process each file
2727
foreach ($files as $file) {
2828
$output_file = PMA_SSL_DIR . "/pma-ssl-$prefix-$counter.$extension";
29-
29+
30+
$file_contents = base64_decode($file, true);
31+
if ($file_contents === false) {
32+
echo 'Failed to decode: ' . $file;
33+
exit(1);
34+
}
35+
3036
// Write the decoded file to the output directory
31-
if (file_put_contents($output_file, base64_decode($file)) === false) {
37+
if (file_put_contents($output_file, $file_contents) === false) {
3238
echo 'Failed to write to ' . $output_file;
3339
exit(1);
3440
}
35-
41+
3642
// Add the output file path to the list
3743
$ssl_files[] = $output_file;
3844
$counter++;

0 commit comments

Comments
 (0)