basic/qa/basic_coverage/test_tdf165420.bas | 35 +++++++++++++++++++++++++++++ basic/source/runtime/methods.cxx | 24 +++++++------------ 2 files changed, 44 insertions(+), 15 deletions(-)
New commits: commit d5700399b8c785e89395090079a3e303ac892bf2 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Feb 25 00:31:35 2025 +0500 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Feb 25 14:07:10 2025 +0100 tdf#165420: handle empty arguments correctly Change-Id: Ib30cce816b2af8a780e09fa04a2129afd91fafe6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182118 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit 37216049f1a699a3269f0e19ee514e814b965266) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182145 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/basic/qa/basic_coverage/test_tdf165420.bas b/basic/qa/basic_coverage/test_tdf165420.bas new file mode 100644 index 000000000000..65da7a10810f --- /dev/null +++ b/basic/qa/basic_coverage/test_tdf165420.bas @@ -0,0 +1,35 @@ +' +' This file is part of the LibreOffice project. +' +' This Source Code Form is subject to the terms of the Mozilla Public +' License, v. 2.0. If a copy of the MPL was not distributed with this +' file, You can obtain one at http://mozilla.org/MPL/2.0/. +' + +Option Explicit + +Function doUnitTest() As String + TestUtil.TestInit + verify_tdf165420() + doUnitTest = TestUtil.GetResult() +End Function + +Sub verify_tdf165420() + On Error GoTo errorHandler + + Dim nHandlerInvocations As Integer + + ' Calling 'Shell' function with an empty argument must not crash + Shell(Empty) + Shell("") + Shell(" ") + + TestUtil.AssertEqual(nHandlerInvocations, 3, "nHandlerInvocations") + + Exit Sub + +errorHandler: + TestUtil.AssertEqual(Err, 5, "Err") ' Expected: Invalid procedure call + nHandlerInvocations = nHandlerInvocations + 1 + Resume Next +End Sub diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 0235db0fc06a..bbc050ff079b 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -3406,30 +3406,21 @@ void SbRtl_Shell(StarBASIC *, SbxArray & rPar, bool) aCmdLine += " " + tmp; } } - else if( aCmdLine.isEmpty() ) - { - // avoid special treatment (empty list) - aCmdLine += " "; - } sal_Int32 nLen = aCmdLine.getLength(); // #55735 if there are parameters, they have to be separated // #72471 also separate the single parameters std::vector<OUString> aTokenVector; - OUString aToken; - sal_Int32 i = 0; - sal_Unicode c; - while( i < nLen ) + for (sal_Int32 i = 0; i < nLen;) { - for ( ;; ++i ) + sal_Unicode c = aCmdLine[i]; + if (c == ' ' || c == ' ') { - c = aCmdLine[ i ]; - if ( c != ' ' && c != ' ' ) - { - break; - } + ++i; + continue; } + OUString aToken; if( c == '\"' || c == '\'' ) { sal_Int32 iFoundPos = aCmdLine.indexOf( c, i + 1 ); @@ -3468,6 +3459,9 @@ void SbRtl_Shell(StarBASIC *, SbxArray & rPar, bool) } // #55735 / #72471 end + if (aTokenVector.empty()) + return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT); + sal_Int16 nWinStyle = 0; if( nArgCount >= 3 ) {