From 1509b0ce6aeb1ec4d3335b8356f5ba318b824f97 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 19 Mar 2026 01:22:37 +0100 Subject: [PATCH] sshserver.pl: pass command-line to `system()` safely Found by Codex Security Follow-up to 89f306ae40b678bd91595ba41fe5f9d5ed374897 #16781 Closes #20996 --- tests/sshserver.pl | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/sshserver.pl b/tests/sshserver.pl index 2132ff2d09..7d445548ac 100755 --- a/tests/sshserver.pl +++ b/tests/sshserver.pl @@ -397,27 +397,24 @@ if((! -e pp($hstprvkeyf)) || (! -s pp($hstprvkeyf)) || unlink(pp($hstprvkeyf), pp($hstpubkeyf), pp($hstpubmd5f), pp($hstpubsha256f), pp($cliprvkeyf), pp($clipubkeyf)); - my $sshkeygenopt = ''; + my @sshkeygenopt; if(($sshid =~ /OpenSSH/) && ($sshvernum >= 560)) { # Override the default key format. Necessary to force legacy PEM format # for libssh2 crypto backends that do not understand the OpenSSH (RFC4716) # format, e.g. WinCNG. # Accepted values: RFC4716, PKCS8, PEM (see also 'man ssh-keygen') - if($ENV{'CURL_TEST_SSH_KEY_FORMAT'}) { - $sshkeygenopt .= ' -m ' . $ENV{'CURL_TEST_SSH_KEY_FORMAT'}; - } - else { - $sshkeygenopt .= ' -m PEM'; # Use the most compatible RSA format for tests. - } + push @sshkeygenopt, '-m'; + # Default to the most compatible RSA format for tests. + push @sshkeygenopt, $ENV{'CURL_TEST_SSH_KEY_FORMAT'} ? $ENV{'CURL_TEST_SSH_KEY_FORMAT'} : 'PEM'; } logmsg "generating host keys...\n" if($verbose); - if(system "\"$sshkeygen\" -q -t rsa -f " . pp($hstprvkeyf) . " -C 'curl test server' -N ''" . $sshkeygenopt) { + if(system($sshkeygen, ('-q', '-t', 'rsa', '-f', pp($hstprvkeyf), '-C', 'curl test server', '-N', '', @sshkeygenopt))) { logmsg "Could not generate host key\n"; exit 1; } display_file_top(pp($hstprvkeyf)) if($verbose); logmsg "generating client keys...\n" if($verbose); - if(system "\"$sshkeygen\" -q -t rsa -f " . pp($cliprvkeyf) . " -C 'curl test client' -N ''" . $sshkeygenopt) { + if(system($sshkeygen, ('-q', '-t', 'rsa', '-f', pp($cliprvkeyf), '-C', 'curl test client', '-N', '', @sshkeygenopt))) { logmsg "Could not generate client key\n"; exit 1; }