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 7AE03A0C53 for ; Wed, 24 Nov 2021 13:34:14 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5C04841165; Wed, 24 Nov 2021 13:34:14 +0100 (CET) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2042.outbound.protection.outlook.com [40.107.94.42]) by mails.dpdk.org (Postfix) with ESMTP id F14584003C; Wed, 24 Nov 2021 13:34:11 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X3DHx4OuRktqYqGrBdq+ilozzzLN50n3PRLK56vQgRsk6dHWuymXVDe1apG/Uy04oLpktiqiH4mw76lXGBMA/zAMfoT7L2Dt3oozOFLhisopKS67Gg60oM6NriVvjkAYAEbwLWE3RhWIlERz9mKwK5PbS2WDQWWHLtneOX/eH6aIrgoCVvZ5DQ2LJbVmWZVFnYTzvM5+MrXhWNAW6lD1oc6QPtQjVY9Fib8CgJPIY4JhzerVlYUVl9RF6vr4VADYzFiz4VJkd4ep+W/LrSP2SRqdl64XrjzVNBx/PSsbzalAQXvT8FP7qmusLEH+xX86Gd4uB/H0JE3b8Xqu3YtqOw== 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=5I5/k7aoL9xQG4ItHLgMAjiEJHmSqDRG4vkRVM7X2ro=; b=LdyAld7Q1odbCnUx3RNmgdN9t1j/foCdisTt/NYVqoMdjheeQDMHVgv+QIl0J1Ns07pQCTy1MLjhb67v0QzrGc5Q1htABCnVl5/jW7743ep9n70bv/XNCx3lO8u58T4pKLg4HBosTYxtm2JWPI+eti6nn8cc58m/BxslvPlLq9mUlUUS0FYNvq6m4ukjBmQH2rfleQHHeT+cSpZ/B91OgFubbveizb84xEwmjCCzRAd853UL8nQd2KzSdrxdM3uCi3fOdcelGaq21Uhell8KQKjYmFuw+BTsLuosVKDguafCTrfLzb45epKCbTKPZbh7+L9nB5CBRJTaC9GiB8mnJQ== 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=5I5/k7aoL9xQG4ItHLgMAjiEJHmSqDRG4vkRVM7X2ro=; b=QZ62ha0ULr9nuJGoKtU9pVKcPH4IwB8gaRtzGT7VCjcg6xX2dMGk90N/fqkupkZ6qtKMs7Liw/OvyTkF/6q8GZ8DiESGtiz7SWXvYxswxD1hXPRwheYbz2Jh9N7DCFOxsYhn3pvOppbJQnAwf04R7gN7BEbdSIt2zruQk8FvSYiv9wtZzGiwfMVc9EFLaqHUUy8BgODhKGGrtMjrptwTdoZgMQVUo0XTdkrznVVFQt0JmZRKiyH77PJWcxZJPHoN4wNAtkowUdvcDr2V35yneC/aJp473C956V1bfMzGwGfvwR/4n+g/siO9sSV7bQkBiIx1QUsLqdPvCo3qzNUjzA== Received: from DM5PR06CA0051.namprd06.prod.outlook.com (2603:10b6:3:37::13) by BN8PR12MB3585.namprd12.prod.outlook.com (2603:10b6:408:49::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.20; Wed, 24 Nov 2021 12:34:10 +0000 Received: from DM6NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:3:37:cafe::d0) by DM5PR06CA0051.outlook.office365.com (2603:10b6:3:37::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21 via Frontend Transport; Wed, 24 Nov 2021 12:34:10 +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 DM6NAM11FT008.mail.protection.outlook.com (10.13.172.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Wed, 24 Nov 2021 12:34:09 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 24 Nov 2021 12:34:06 +0000 From: Gregory Etelson To: , CC: Ferruh Yigit , , "Viacheslav Ovsiienko" , Ori Kam , Xiaoyun Li , Wei Zhao Subject: [PATCH v3] app/testpmd: fix hex string parser input length Date: Wed, 24 Nov 2021 14:33:54 +0200 Message-ID: <20211124123354.6462-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.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bcde1603-c37a-44f2-b92b-08d9af46b6a1 X-MS-TrafficTypeDiagnostic: BN8PR12MB3585: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:291; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eZa6U29KRD34RQX+dhO7eMl0faVMnsZ5tkWftExThpzOayWdjSXzKNazKvY6gvN0mwK+UELFvRxWF9+l2zsslVv/d/op8PHD0RIeZR18JyhxYOutsYfsoKLdyUFOzkoVHcpVl0j4lxvtKCBMsXf197rwHYFkKZRssKjlZr09YPls1pmX5JWDsR3WxPJWeiLVmX42uZKmDuVzH0wrqefl9V1b5Fm/pO+krYsNBqGzUKphqJhONefoTJvopWCrSESH34PLegzVxy1IiFupKh/GX+4gbDSQ3DJZQZ+tqJSJ8o3gA/CXVAM8S9tUcMPjr9zWdTyd+8EqCUxeBCFTfqZKs0nxAX9VWVgHGYdeTtFCslb4nfug9YGJwW5yILTxOJHZ4VbSmyOtnz1DMNyGLuw+XFsRdrxjgGgnRs7TomQ7KHslLVugXrzs3PT5txwIIEB1bN9jsefFZxJj3aeNsb6jM6RYgwLjmpV5hSzkJsxwfeWVMCYHi4eZN9tjVe2kOtbsFHJLAJxOqrI5e3V/pB1coy3ZJdZvion8KH6dVKLQktdaBlQVmdBS5p0p+II0tdcEvA23mxX5vNjrKoN/bxDs3vFxYX7XnGUg4lyzxg6AhHEUdUB9wOZxOHHM37/26AWysCoXvOQBC2kMEJp2oOqKETA/H5HMZD299YxY6Z3EiN6I25+dfQLDlmrvhXSAp/6LyhjvJlYECjqZ37sMScfv7g== 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)(36840700001)(46966006)(186003)(54906003)(16526019)(7049001)(2906002)(6286002)(7696005)(26005)(7636003)(70586007)(8936002)(508600001)(70206006)(4326008)(55016003)(36860700001)(82310400004)(336012)(316002)(426003)(110136005)(6666004)(1076003)(5660300002)(83380400001)(8676002)(356005)(36756003)(47076005)(2616005)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2021 12:34:09.4220 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bcde1603-c37a-44f2-b92b-08d9af46b6a1 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: DM6NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3585 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-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 strings with even and odd length. Parse result of an input with odd length will match result of even length input, that has `0` as MSB, following by the original sequence. For example: "0x1" results in *dst={0x01, 0x00}, *size=1 "0xabc" results in *dst={0x0a, 0xbc, 0x00}, *size=2 Cc: stable@dpdk.org Fixes: 169a9fed1f4c ("app/testpmd: fix hex string parser support for flow API") Signed-off-by: Gregory Etelson Reviewed-by: Viacheslav Ovsiienko --- v2: Return error after snprintf failure. v3: Update returned size. Update the patch comment. --- app/test-pmd/cmdline_flow.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 1b00ae507b..bbe3dc0115 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -7702,9 +7702,8 @@ 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; + const uint8_t *head = dst; /* Check input parameters */ if ((src == NULL) || @@ -7714,19 +7713,23 @@ 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 = (uint32_t)(dst - head); return -1; } + left -= read_lim; + src += read_lim; + dst++; } - dst[len] = 0; - *size = len; - + *dst = 0; + *size = (uint32_t)(dst - head); return 0; } -- 2.34.0