From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9F670A0C4C; Tue, 23 Nov 2021 12:58:12 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 67BC940040; Tue, 23 Nov 2021 12:58:12 +0100 (CET) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam07on2049.outbound.protection.outlook.com [40.107.95.49]) by mails.dpdk.org (Postfix) with ESMTP id 5341A4003C; Tue, 23 Nov 2021 12:58:11 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cZXNmpbR/eS4rpPjt30Llm8KK6LDY+WcbjUDtHtsCoKNfUrZ1x5jPjJQ0RfSNRPwDeDAPcdjio9M9T7yqmQr8qgiCz7z3jaw6V2amI12qUxQPMYM4KkLm9wltk7VlDn3JJ/8pVTR9jtGu64ZYDAf17JkYeINZ58EykwR2K8HX8E1CCfcW8toUdWORkHp0hwLS8165Y53ByOGRt87V8NNgt6rGPkc51nUvdNd4mYCOEJVa0KfiH9R8ZJf54umEzrNwN9gnvx4zQ9BEnmBlsT28HaY91C3QAxlTCr46YB2hHx3AD83yN5HxTxNDmeNDPloIV1+vF7L3OA80dki9NOeww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AeIql2Z/5dPbYGNzx9FQUslVcOdfPN8NvQjgNda/BKg=; b=KoFqO5ViVUfDKLOp4BWAkZhjuCje5ImcEIoKs67VhHobzCxEhAxj2yc6FE5tT7JYnSFjrwQWC8o5gVdZJ8NdSXzV+jnMuOxo/q6gHowT8y7JjNKCqdXuoXGB6ON8bCcLfN4k+A8V3aSvpazlW6S7lIc5aRrBjrCQzLnK6oMU2lNJsDmk8cvjiJc0sjWMUz/T1MK4DV/HeuhtDja16dRsLvXD6H9LkJPmD62SHU6IgoAD4NYAobpVsNRvxX78miTJvSoO5fp+NkF/oBG8aQA/HrphrjG5T+eGWQSGYqeSHzPSIPyOPRctBt9ORDe3kpY9tumDDw9mfC2sIB1s7Vw3nQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AeIql2Z/5dPbYGNzx9FQUslVcOdfPN8NvQjgNda/BKg=; b=EOYiCigxVkbApdJ3Nkq/NTT4pk5tFBpfGIrfJpEhcoCw+Rqr0f0lCd7mcLO1WfR8roALcdq9ImnZ/KJnZw6YFcbVZ9Kc6V751KRSF/UscouFOhM06T/8jasEtNPoUtYFtwVn6nrBp4+D6AfXrRqEWuLM7MEJytAmiHSPXOzn/meUlnd0J8+wtYzKgC9X0VyXlTcSiE8vXvn99uSZLUiHjnNLWPwM0E+LjoOS/0mzZ4ic6GoNWcpxmBkfW/pl/ljYw6oL5WoiKa1f+SaJHlrHyf6ts1Kpn7eiX7wo44PB0Zjh1BTdDxDiXUFLdz0C/bcfd0+tUBDKpj9JhQ/cwufe3A== Received: from DM6PR07CA0098.namprd07.prod.outlook.com (2603:10b6:5:337::31) by BN8PR12MB3570.namprd12.prod.outlook.com (2603:10b6:408:4a::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Tue, 23 Nov 2021 11:58:07 +0000 Received: from DM6NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:5:337:cafe::e4) by DM6PR07CA0098.outlook.office365.com (2603:10b6:5:337::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22 via Frontend Transport; Tue, 23 Nov 2021 11:58:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT017.mail.protection.outlook.com (10.13.172.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Tue, 23 Nov 2021 11:58:06 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 23 Nov 2021 11:58:03 +0000 From: Gregory Etelson To: , CC: Ferruh Yigit , , Ori Kam , Xiaoyun Li , Wei Zhao Subject: [PATCH v2] app/testpmd: fix hex string parser input length Date: Tue, 23 Nov 2021 13:57:51 +0200 Message-ID: <20211123115751.29038-1-getelson@nvidia.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211123090005.24707-1-getelson@nvidia.com> References: <20211123090005.24707-1-getelson@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 611c939f-fcce-46f7-0dcc-08d9ae788323 X-MS-TrafficTypeDiagnostic: BN8PR12MB3570: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:197; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U8TxWYkx8HtnQeW249jim2MhIxWFaRhsppvcrTav9JGqSYCcAuwnsqu+cabpxo+CIr58HYIwuZnaSw1QhwqLuVMQnHJONr0GL19HNXidYjEYP0p5XNaQJurIsTZlbjqZLNfeCDERVKzPFBr0dOs/uwr4esG0GmH6oFHhuOVEj7WfydnMO5UnwkXpZMAh9bR5D4Y5G9N4uTxaCPkaSxSXks5Z0OM6U3o7Cq6C1SLFvHb074Tov2SGYXdqJ53rpSBa+QbOs2GoaXSDZWQORc4q7US4hlzT2TK6XlkdyoqE2LNvR8Ql2o97Ya7RSQB3fdOdkku/bnz2BGnN554WoTS6dXlflwBsYCtTROi/n5mot1JbIfdz0sMJG3KfwAcA78UanWj6MQO0FyzxHr/4R5G2nsDBcizr5i109jyD2MSEjFe4tLb+mNJ7tN4YS7X7JkCCeSdio9aoQPQVHM+T0wV7f8zBLDpiV3OOO3BxvwYZ/xp5eysyLZF7yVjGvnIuVYe3GnGtvS3f7ZoWgjefMqxK2Fv/yrdp2praulXX+BORf4wUh6c5R76SFKiDPBHdkcwNp7zhpAkaw4Rw+/CRONW6D6aLbWj/nkqeYF7w9ooZWISog2/0xLDIaV8GFR5kS8PZXk+xQVgUFYK5NMOn9tha2Za0dhz4RrHTDY+IjQEGVaMa+X0mzB186D6wcsxCfO4YCofAKJpKFq6yUbEMNIvNFA== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(70586007)(8676002)(8936002)(4326008)(70206006)(186003)(6286002)(6666004)(508600001)(16526019)(2616005)(336012)(7049001)(55016003)(82310400004)(426003)(36756003)(5660300002)(26005)(36860700001)(7696005)(54906003)(110136005)(1076003)(86362001)(356005)(7636003)(316002)(47076005)(83380400001)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2021 11:58:06.7937 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 611c939f-fcce-46f7-0dcc-08d9ae788323 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3570 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Current hex string parser assumes input has even characters number. The parser fails input string with odd length. The patch parses hex stringhs with even and odd length. Cc: stable@dpdk.org Fixes: 169a9fed1f4c ("app/testpmd: fix hex string parser support for flow API") Signed-off-by: Gregory Etelson --- v2: return error after snprintf failure. --- app/test-pmd/cmdline_flow.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 1b00ae507b..dcf8ebec45 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -7702,9 +7702,7 @@ parse_string(struct context *ctx, const struct token *token, static int parse_hex_string(const char *src, uint8_t *dst, uint32_t *size) { - char *c = NULL; - uint32_t i, len; - char tmp[3]; + uint32_t left = *size; /* Check input parameters */ if ((src == NULL) || @@ -7714,19 +7712,22 @@ parse_hex_string(const char *src, uint8_t *dst, uint32_t *size) return -1; /* Convert chars to bytes */ - for (i = 0, len = 0; i < *size; i += 2) { - snprintf(tmp, 3, "%s", src + i); - dst[len++] = strtoul(tmp, &c, 16); - if (*c != 0) { - len--; - dst[len] = 0; - *size = len; + while (left) { + char tmp[3], *end = tmp; + uint32_t read_lim = left & 1 ? 1 : 2; + + snprintf(tmp, read_lim + 1, "%s", src); + *dst = strtoul(tmp, &end, 16); + if (*end) { + *dst = 0; + *size = *size - left; return -1; } + left -= read_lim; + src += read_lim; + dst++; } - dst[len] = 0; - *size = len; - + *dst = 0; return 0; } -- 2.34.0