From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 EEDE0211F888D for ; Tue, 26 Jun 2018 14:05:58 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2018 14:05:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,275,1526367600"; d="scan'208";a="60382373" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by FMSMGA003.fm.intel.com with ESMTP; 26 Jun 2018 14:05:58 -0700 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 26 Jun 2018 14:05:58 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.125]) by fmsmsx158.amr.corp.intel.com ([169.254.15.52]) with mapi id 14.03.0319.002; Tue, 26 Jun 2018 14:05:58 -0700 From: "Carsey, Jaben" To: "Bi, Dandan" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Ni, Ruiyu" Thread-Topic: [patch] ShellPkg/DP: Add more check for input parameters Thread-Index: AQHUDQxsgrjRcy3XZ0CTxbpFOiYnEKRzCNYA Date: Tue, 26 Jun 2018 21:05:58 +0000 Message-ID: References: <20180626051240.170588-1-dandan.bi@intel.com> In-Reply-To: <20180626051240.170588-1-dandan.bi@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYWIwZjMwMDAtNDViZC00NzY4LTk0ZmMtNmRjMzBhODczZWUwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiWDN6b0R2MktWZjZ5cDJwRTU5SFFKR1RwZjJPRENLdytjZEljWFJzeFRYMk96MkRQQTFrZGM1dVJpVzBacW5peiJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-originating-ip: [10.1.200.106] MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Tue, 26 Jun 2018 21:05:59 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jaben Carsey > -----Original Message----- > From: Bi, Dandan > Sent: Monday, June 25, 2018 10:13 PM > To: edk2-devel@lists.01.org > Cc: Gao, Liming ; Ni, Ruiyu ; > Carsey, Jaben > Subject: [patch] ShellPkg/DP: Add more check for input parameters > Importance: High >=20 > 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. >=20 > Cc: Liming Gao > Cc: Ruiyu Ni > Cc: Jaben Carsey > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Dandan Bi > --- > ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c | 105 > ++++++++++++++++-------- > ShellPkg/DynamicCommand/DpDynamicCommand/Dp.uni | 6 ++ > 2 files changed, 77 insertions(+), 34 deletions(-) >=20 > diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c > b/ShellPkg/DynamicCommand/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), > mDpHiiHandle); > return SHELL_INVALID_PARAMETER; > + } else if (ShellCommandLineGetCount(ParamPackage) > 1){ > + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TOO_MANY), > mDpHiiHandle); > + 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), > mDpHiiHandle, 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), > mDpHiiHandle); > + return SHELL_INVALID_PARAMETER; > + } else { > + if (!(RawMode || AllMode)) { > + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_NO_RAW_ALL), > mDpHiiHandle); > + return SHELL_INVALID_PARAMETER; > + } > + Status =3D ShellConvertStringToUint64(CmdLineArg, &Intermediate, F= ALSE, > TRUE); > + if (EFI_ERROR (Status)) { > + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN > (STR_DP_INVALID_NUM_ARG), mDpHiiHandle, L"-n"); > + return SHELL_INVALID_PARAMETER; > + } else { > + Number2Display =3D (UINTN)Intermediate; > + if (Number2Display =3D=3D 0 || Number2Display > > MAXIMUM_DISPLAYCOUNT) { > + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN > (STR_DP_INVALID_RANGE), 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), > mDpHiiHandle); > + return SHELL_INVALID_PARAMETER; > + } else { > + Status =3D ShellConvertStringToUint64(CmdLineArg, &Intermediate, F= ALSE, > TRUE); > + if (EFI_ERROR (Status)) { > + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN > (STR_DP_INVALID_NUM_ARG), 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), > mDpHiiHandle); > + 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- > >Name, NameSize); > - } > - > // > // Timer specific processing > // > // Get the Performance counter characteristics: > // Freq =3D Frequency in Hz > diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.uni > b/ShellPkg/DynamicCommand/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 > arguments\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 hand= les > error - %r\n" > #string STR_DP_ERROR_NAME #language en-US "Unknown driver > name" > #string STR_PERF_PROPERTY_NOT_FOUND #language en-US > "Performance property not found\n" > #string STR_DP_BUILD_REVISION #language en-US "\nDP Build > Version: %d.%d\n" > #string STR_DP_KHZ #language en-US "System Performa= nce > Timer Frequency: %,8d (KHz)\n" > -- > 2.14.3.windows.1