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 85DE6A0A0C; Sat, 12 Jun 2021 00:49:36 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 02BA24014F; Sat, 12 Jun 2021 00:49:36 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2070.outbound.protection.outlook.com [40.107.237.70]) by mails.dpdk.org (Postfix) with ESMTP id 089674003F for ; Sat, 12 Jun 2021 00:49:34 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bDCKTe9Nc+gtW1MPJc/dZ83sfvZxSrzKR7W8X5W47RXw6egJdqAQiWrtcvDnk6MBTQTsobs/UwUdOVqDd+O0opKbogsIm6LJjJMPs0k/9myl3ctjWjvVMUeRgnP3wvpTS2pkWXEp5wLt9h7dH3kiP2eWk/ht0W18t+I6c06UNrUNi/IXBmka0SRtzOWwvKJkePqZmE7mXavTAIFz4tOmPIHm+9gpC+bIM99vQOEBa3cAai6iEDOUiZ2g0yEGtVxgZJELuu+2t33k9HGDZ7zugZUfBWY+FRJk7pGbGpYQWl7I8PEY3ZfdqvElJC9aCcthYdSjH9CkFW0I7y02hvYC8g== 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-SenderADCheck; bh=jVgBPYHcyMNhsN+9gWJ2+cu1xOLdFOJ/LYN50W6UcAk=; b=JAobq2VjFccuO2pbnw2v8F87UBUBwQnB40dGG1TE/Fjz7QO5VYN5/24KjlfMHnEa9XcUy4k0YenpnEGm6WlwAYQ9QJxctU35h3rEebuU82tEdG1TKcYEJstMQ3se2tUu07TrYaOZIJElH4K5falz8BSxGCf5fQPB/duv5U/N/1FaKt1/EbZTkRbmY1YmNpnJMhAS1zEMX2csmJ1IJjvMxqwBF3twr47I9zpA0deF4O7OcCoi/adY8AR8ysxjXc/PD6Oq1EydjdUuQikR9On4YekUd86ogx+sK2PR5PI6xJ/nBTrcwbFC/IHdjr8/PwVSijtDmo0DPDPSo/l2+wdSAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=marvell.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=jVgBPYHcyMNhsN+9gWJ2+cu1xOLdFOJ/LYN50W6UcAk=; b=f0+crGMEt1V3fbk7uqZBwSaZzB274D2Y2tGcECyBq93oRsE5OGrxMOHKFA9slAgd8e3bGBpANM26kjePHKmiEj8H6795USFovMgonIdNk8WM3vT7lH+s5oyCiyrQ3Idr+pvCOVHXFFx1WD7XMC33s4EuZ5udUYNaYuzHHGYM/n0ygOryce5FtGwvFVo4Amnm8MGZ6ZLJNyuw4UwMqFWbK4RccXuI+kfnd8+UATT/+kgFmRhOwMzQ+TYeoCWnDFuN1VQN0PSG2Dx4YVo/xMvVhg6Htk0w34Ij/KKeYxHIrPhsS5ajhSLjxSgZcR6qZElKtEjrP88QwqU9d8le9OP4EQ== Received: from MWHPR14CA0042.namprd14.prod.outlook.com (2603:10b6:300:12b::28) by BY5PR12MB3699.namprd12.prod.outlook.com (2603:10b6:a03:195::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.22; Fri, 11 Jun 2021 22:49:33 +0000 Received: from CO1NAM11FT030.eop-nam11.prod.protection.outlook.com (2603:10b6:300:12b:cafe::5e) by MWHPR14CA0042.outlook.office365.com (2603:10b6:300:12b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21 via Frontend Transport; Fri, 11 Jun 2021 22:49:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; marvell.com; dkim=none (message not signed) header.d=none;marvell.com; 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 CO1NAM11FT030.mail.protection.outlook.com (10.13.174.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4219.21 via Frontend Transport; Fri, 11 Jun 2021 22:49:32 +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.2; Fri, 11 Jun 2021 22:49:30 +0000 From: Xueming Li To: CC: Thomas Monjalon , , , Jerin Jacob , Sunil Kumar Kori , Kiran Kumar K , "Nithin Dabilpuram" Date: Sat, 12 Jun 2021 06:49:07 +0800 Message-ID: <20210611224907.1904-1-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 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: 54cebed2-7b24-43de-a520-08d92d2b2e01 X-MS-TrafficTypeDiagnostic: BY5PR12MB3699: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: it7nyYGQCy+G0tnP9xY1e95Xu1bm5lDyqsmWrfkBhcCd1omE6IJlsqkQDpCT4SJ5ksNTd685ok7nkxlqo9E2LjDAztkQTBWL7lX8MNkaOSbssKNNUMpnwXS/p+WqxNasEijp4drJDcb+GQwuYBU6XEqcCLiGQTAiN2NWKc3fOWajnKvdo8Rf+Lm05vUSH/upszNeFKl7R0qMHbY8GFr70ZEqmqWX1uzzTJYZUW+BN+0mgcf9KOX69qZdaDNJwkezU8FLPofFMoJcJrii4F3lteDretzBlvS2Dx5/uQbf7i3r9V8rakS0CoC+XIb84Rf1QP6U8pwHjcHNW9wiDP/IFdpeMzENYbeJHnAwQSS/8Vl2xy6TuIMQn7eLRRPykDKov7KM96Jz/TgHKuuprPZN5ye/zoNq9uavffqOGhYGu5gj5TN9AsuxvCcrboePIPuSk+s7U2V1SaYGA1b9tL96jAHKsdbyL0DNhEqKRRZloS5qcX1SwLkb9/uWfPlrgsOf5WMmDwCDU1G6fWYMOYo+tJpjZgpJnIg+VqOeQJvWmo5V5+NghBwrjv2egjQitDaQg4G2Y2hFcsLH7fzubeSJU/skSNpMI22V3A5hzSPfXo2AbSlw+/7rSNDTbx2J+Inpo2EwR5YIf+3qK/CzwGn/cQPgukmpKZslRtahnHBb0EA= 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)(136003)(396003)(346002)(376002)(39860400002)(36840700001)(46966006)(7636003)(83380400001)(26005)(186003)(426003)(82310400003)(16526019)(356005)(82740400003)(36756003)(6286002)(36860700001)(109986005)(47076005)(54906003)(6666004)(5660300002)(478600001)(36906005)(1076003)(336012)(7696005)(2906002)(70206006)(8676002)(2616005)(86362001)(55016002)(70586007)(4326008)(316002)(8936002)(266003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2021 22:49:32.7279 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 54cebed2-7b24-43de-a520-08d92d2b2e01 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: CO1NAM11FT030.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3699 Subject: [dpdk-dev] [PATCH] eal: save error in string copy 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 Sender: "dev" From: Thomas Monjalon Sets rte_errrno if the destination buffer is too small. Signed-off-by: Thomas Monjalon --- lib/eal/common/eal_common_string_fns.c | 4 +++- lib/eal/common/eal_common_trace.c | 1 - lib/eal/include/rte_string_fns.h | 5 ++--- lib/graph/node.c | 12 +++--------- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/eal/common/eal_common_string_fns.c b/lib/eal/common/eal_common_string_fns.c index 60c5dd66f9..ddd1891656 100644 --- a/lib/eal/common/eal_common_string_fns.c +++ b/lib/eal/common/eal_common_string_fns.c @@ -8,6 +8,7 @@ #include #include +#include /* split string into tokens */ int @@ -62,5 +63,6 @@ rte_strscpy(char *dst, const char *src, size_t dsize) /* Not enough room in dst, set NUL and return error. */ if (res != 0) dst[res - 1] = '\0'; - return -E2BIG; + rte_errno = E2BIG; + return -rte_errno; } diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index 24e27387b1..7bff1cd2ce 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -500,7 +500,6 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name, /* Initialize the trace point */ if (rte_strscpy(tp->name, name, TRACE_POINT_NAME_SIZE) < 0) { trace_err("name is too long"); - rte_errno = E2BIG; goto free; } diff --git a/lib/eal/include/rte_string_fns.h b/lib/eal/include/rte_string_fns.h index 8bac8243c9..bb43b2cba3 100644 --- a/lib/eal/include/rte_string_fns.h +++ b/lib/eal/include/rte_string_fns.h @@ -97,8 +97,6 @@ rte_strlcat(char *dst, const char *src, size_t size) * Copy string src to buffer dst of size dsize. * At most dsize-1 chars will be copied. * Always NUL-terminates, unless (dsize == 0). - * Returns number of bytes copied (terminating NUL-byte excluded) on success ; - * negative errno on error. * * @param dst * The destination string. @@ -110,8 +108,9 @@ rte_strlcat(char *dst, const char *src, size_t size) * Length in bytes of the destination buffer. * * @return - * The number of bytes copied on success + * The number of bytes copied (terminating NUL-byte excluded) on success. * -E2BIG if the destination buffer is too small. + * rte_errno is set. */ ssize_t rte_strscpy(char *dst, const char *src, size_t dsize); diff --git a/lib/graph/node.c b/lib/graph/node.c index 873c9ab16d..86ec4316f9 100644 --- a/lib/graph/node.c +++ b/lib/graph/node.c @@ -86,10 +86,8 @@ __rte_node_register(const struct rte_node_register *reg) } /* Initialize the node */ - if (rte_strscpy(node->name, reg->name, RTE_NODE_NAMESIZE) < 0) { - rte_errno = E2BIG; + if (rte_strscpy(node->name, reg->name, RTE_NODE_NAMESIZE) < 0) goto free; - } node->flags = reg->flags; node->process = reg->process; node->init = reg->init; @@ -98,10 +96,8 @@ __rte_node_register(const struct rte_node_register *reg) node->parent_id = reg->parent_id; for (i = 0; i < reg->nb_edges; i++) { if (rte_strscpy(node->next_nodes[i], reg->next_nodes[i], - RTE_NODE_NAMESIZE) < 0) { - rte_errno = E2BIG; + RTE_NODE_NAMESIZE) < 0) goto free; - } } node->id = node_id++; @@ -278,10 +274,8 @@ edge_update(struct node *node, struct node *prev, rte_edge_t from, /* Update the new nodes name */ for (i = from; i < max_edges; i++, count++) { if (rte_strscpy(node->next_nodes[i], next_nodes[count], - RTE_NODE_NAMESIZE) < 0) { - rte_errno = E2BIG; + RTE_NODE_NAMESIZE) < 0) goto restore; - } } restore: /* Update the linked list to point new node address in prev node */ -- 2.25.1