From nobody Thu May 2 20:57:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 15299900008660.9132301404007421; Mon, 25 Jun 2018 22:13:20 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CE5E6202E540A; Mon, 25 Jun 2018 22:13:19 -0700 (PDT) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0D5A8202E5401 for ; Mon, 25 Jun 2018 22:13:17 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jun 2018 22:13:16 -0700 Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by fmsmga005.fm.intel.com with ESMTP; 25 Jun 2018 22:13:15 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=dandan.bi@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,273,1526367600"; d="scan'208";a="240294447" From: Dandan Bi To: edk2-devel@lists.01.org Date: Tue, 26 Jun 2018 13:12:40 +0800 Message-Id: <20180626051240.170588-1-dandan.bi@intel.com> X-Mailer: git-send-email 2.14.3.windows.1 Subject: [edk2] [patch] ShellPkg/DP: Add more check for input parameters X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jaben Carsey , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" New added checkers includes: 1. Too many invalid parameters 2. Too few parameter 3. Invalid number parameter for -n and -t flag 4. Conflict parameter of -A and -R. Cc: Liming Gao Cc: Ruiyu Ni Cc: Jaben Carsey Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi Reviewed-by: Jaben Carsey --- ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c | 105 ++++++++++++++++----= ---- ShellPkg/DynamicCommand/DpDynamicCommand/Dp.uni | 6 ++ 2 files changed, 77 insertions(+), 34 deletions(-) diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c b/ShellPkg/Dynam= icCommand/DpDynamicCommand/Dp.c index 38766613175..dea9ff85738 100644 --- a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c +++ b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c @@ -718,10 +718,11 @@ RunDp ( CONST CHAR16 *CustomCumulativeToken; PERF_CUM_DATA *CustomCumulativeData; UINTN NameSize; SHELL_STATUS ShellStatus; TIMER_INFO TimerInfo; + UINT64 Intermediate; =20 StringPtr =3D NULL; SummaryMode =3D FALSE; VerboseMode =3D FALSE; AllMode =3D FALSE; @@ -742,10 +743,13 @@ RunDp ( // Status =3D ShellCommandLineParse (ParamList, &ParamPackage, NULL, TRUE); if (EFI_ERROR(Status)) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_INVALID_ARG), mDpH= iiHandle); return SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount(ParamPackage) > 1){ + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TOO_MANY), mDpHiiH= andle); + return SHELL_INVALID_PARAMETER; } =20 // // Boolean options // @@ -755,28 +759,84 @@ RunDp ( RawMode =3D ShellCommandLineGetFlag (ParamPackage, L"-R"); ExcludeMode =3D ShellCommandLineGetFlag (ParamPackage, L"-x"); mShowId =3D ShellCommandLineGetFlag (ParamPackage, L"-i"); CumulativeMode =3D ShellCommandLineGetFlag (ParamPackage, L"-c"); =20 + if (AllMode && RawMode) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CONFLICT_ARG), mDp= HiiHandle, L"-A", L"-R"); + return SHELL_INVALID_PARAMETER; + } + // Options with Values - CmdLineArg =3D ShellCommandLineGetValue (ParamPackage, L"-n"); - if (CmdLineArg =3D=3D NULL) { - Number2Display =3D DEFAULT_DISPLAYCOUNT; - } else { - Number2Display =3D StrDecimalToUintn(CmdLineArg); - if (Number2Display =3D=3D 0) { - Number2Display =3D MAXIMUM_DISPLAYCOUNT; + if (ShellCommandLineGetFlag (ParamPackage, L"-n")) { + CmdLineArg =3D ShellCommandLineGetValue (ParamPackage, L"-n"); + if (CmdLineArg =3D=3D NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TOO_FEW), mDpHii= Handle); + return SHELL_INVALID_PARAMETER; + } else { + if (!(RawMode || AllMode)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_NO_RAW_ALL), m= DpHiiHandle); + return SHELL_INVALID_PARAMETER; + } + Status =3D ShellConvertStringToUint64(CmdLineArg, &Intermediate, FAL= SE, TRUE); + if (EFI_ERROR (Status)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_INVALID_NUM_AR= G), mDpHiiHandle, L"-n"); + return SHELL_INVALID_PARAMETER; + } else { + Number2Display =3D (UINTN)Intermediate; + if (Number2Display =3D=3D 0 || Number2Display > MAXIMUM_DISPLAYCOU= NT) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_INVALID_RANG= E), mDpHiiHandle, L"-n", 0, MAXIMUM_DISPLAYCOUNT); + return SHELL_INVALID_PARAMETER; + } + } } + } else { + Number2Display =3D DEFAULT_DISPLAYCOUNT; } =20 - CmdLineArg =3D ShellCommandLineGetValue (ParamPackage, L"-t"); - if (CmdLineArg =3D=3D NULL) { - mInterestThreshold =3D DEFAULT_THRESHOLD; // 1ms :=3D 1,000 us + if (ShellCommandLineGetFlag (ParamPackage, L"-t")) { + CmdLineArg =3D ShellCommandLineGetValue (ParamPackage, L"-t"); + if (CmdLineArg =3D=3D NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TOO_FEW), mDpHii= Handle); + return SHELL_INVALID_PARAMETER; + } else { + Status =3D ShellConvertStringToUint64(CmdLineArg, &Intermediate, FAL= SE, TRUE); + if (EFI_ERROR (Status)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_INVALID_NUM_AR= G), mDpHiiHandle, L"-t"); + return SHELL_INVALID_PARAMETER; + } else { + mInterestThreshold =3D Intermediate; + } + } } else { - mInterestThreshold =3D StrDecimalToUint64(CmdLineArg); + mInterestThreshold =3D DEFAULT_THRESHOLD; // 1ms :=3D 1,000 us } =20 + if (ShellCommandLineGetFlag (ParamPackage, L"-c")) { + CustomCumulativeToken =3D ShellCommandLineGetValue (ParamPackage, L"-c= "); + if (CustomCumulativeToken =3D=3D NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TOO_FEW), mDpHii= Handle); + return SHELL_INVALID_PARAMETER; + } else { + CustomCumulativeData =3D AllocateZeroPool (sizeof (PERF_CUM_DATA)); + if (CustomCumulativeData =3D=3D NULL) { + ShellStatus =3D SHELL_OUT_OF_RESOURCES; + goto Done; + } + CustomCumulativeData->MinDur =3D PERF_MAXDUR; + CustomCumulativeData->MaxDur =3D 0; + CustomCumulativeData->Count =3D 0; + CustomCumulativeData->Duration =3D 0; + NameSize =3D StrLen (CustomCumulativeToken) + 1; + CustomCumulativeData->Name =3D AllocateZeroPool (NameSize); + if (CustomCumulativeData->Name =3D=3D NULL) { + ShellStatus =3D SHELL_OUT_OF_RESOURCES; + goto Done; + } + UnicodeStrToAsciiStrS (CustomCumulativeToken, CustomCumulativeData->= Name, NameSize); + } + } =20 // // DP dump performance data by parsing FPDT table in ACPI table. // Folloing 3 steps are to get the measurement form the FPDT table. // @@ -816,33 +876,10 @@ RunDp ( // // Initialize the Summary data. // InitSummaryData (); =20 - // - // Init the custom cumulative data. - // - CustomCumulativeToken =3D ShellCommandLineGetValue (ParamPackage, L"-c"); - if (CustomCumulativeToken !=3D NULL) { - CustomCumulativeData =3D AllocateZeroPool (sizeof (PERF_CUM_DATA)); - if (CustomCumulativeData =3D=3D NULL) { - ShellStatus =3D SHELL_OUT_OF_RESOURCES; - goto Done; - } - CustomCumulativeData->MinDur =3D PERF_MAXDUR; - CustomCumulativeData->MaxDur =3D 0; - CustomCumulativeData->Count =3D 0; - CustomCumulativeData->Duration =3D 0; - NameSize =3D StrLen (CustomCumulativeToken) + 1; - CustomCumulativeData->Name =3D AllocateZeroPool (NameSize); - if (CustomCumulativeData->Name =3D=3D NULL) { - ShellStatus =3D SHELL_OUT_OF_RESOURCES; - goto Done; - } - UnicodeStrToAsciiStrS (CustomCumulativeToken, CustomCumulativeData->Na= me, NameSize); - } - // // Timer specific processing // // Get the Performance counter characteristics: // Freq =3D Frequency in Hz diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.uni b/ShellPkg/Dyn= amicCommand/DpDynamicCommand/Dp.uni index ced8a487428..bde499fb873 100644 --- a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.uni +++ b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.uni @@ -31,10 +31,16 @@ #string STR_DP_UP #language en-US "UP" #string STR_DP_DOWN #language en-US "DOWN" #string STR_DP_DASHES #language en-US "-----------------= --------------------------------------------------------------\n" #string STR_DP_SECTION_HEADER #language en-US "\n=3D=3D[ %s ]=3D= =3D=3D=3D=3D=3D=3D=3D\n" #string STR_DP_INVALID_ARG #language en-US "Invalid argument(= s)\n" +#string STR_DP_TOO_MANY #language en-US "Too many argument= s\n" +#string STR_DP_TOO_FEW #language en-US "Too few arguments= \n" +#string STR_DP_INVALID_NUM_ARG #language en-US "Invalid argument(= s), the value of %H%s%N must be numbers\n" +#string STR_DP_INVALID_RANGE #language en-US "Invalid argument(= s), the value of %H%s%N must be between %H%d%N and %H%d%N\n" +#string STR_DP_CONFLICT_ARG #language en-US "Invalid argument(= s), %H%s%N can not be used together with %H%s%N\n" +#string STR_DP_NO_RAW_ALL #language en-US "Invalid argument(= s), -n flag must use with -A or -R\n" #string STR_DP_HANDLES_ERROR #language en-US "Locate all handle= s error - %r\n" #string STR_DP_ERROR_NAME #language en-US "Unknown driver na= me" #string STR_PERF_PROPERTY_NOT_FOUND #language en-US "Performance prope= rty not found\n" #string STR_DP_BUILD_REVISION #language en-US "\nDP Build Versio= n: %d.%d\n" #string STR_DP_KHZ #language en-US "System Performanc= e Timer Frequency: %,8d (KHz)\n" --=20 2.14.3.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel