From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3472FA09EA for ; Tue, 8 Dec 2020 18:00:42 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 00789C908; Tue, 8 Dec 2020 18:00:41 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 7A3CD98; Tue, 8 Dec 2020 18:00:37 +0100 (CET) IronPort-SDR: 37Dq0oqBkKqs6fbXaoT5Rvgn//PPvFz34ry8XfoQXA7/UOM1jN/XUL6I+fgmQQPeW+QkngXlu9 Y7iSdi6Qci5A== X-IronPort-AV: E=McAfee;i="6000,8403,9829"; a="153164696" X-IronPort-AV: E=Sophos;i="5.78,402,1599548400"; d="scan'208";a="153164696" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2020 09:00:35 -0800 IronPort-SDR: MNPNsqU1qWJIC9p4AwA9vFJjuUciqyuHDsshck3uL75GN+wcxenoP9mPM/8hiS5gGZjezGi5bW JrC/GnP6lq7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,402,1599548400"; d="scan'208";a="552289029" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by orsmga005.jf.intel.com with ESMTP; 08 Dec 2020 09:00:33 -0800 From: Vladimir Medvedkin To: dev@dpdk.org Cc: david.marchand@redhat.com, vladimir.medvedkin@intel.com, stable@dpdk.org Date: Tue, 8 Dec 2020 17:00:04 +0000 Message-Id: <1607446804-160076-1-git-send-email-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-stable] [PATCH] rib: fix undefined behavior X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 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 Sender: "stable" According to GCC documentation for __builtin_clz: Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined. __builtin_clz will be called with 0 if the existing prefix address matches the one we want to insert. Fixes: 5a5793a5ffa2 ("rib: add RIB library") Cc: vladimir.medvedkin@intel.com Cc: stable@dpdk.org Reported-by: David Marchand Signed-off-by: Vladimir Medvedkin --- lib/librte_rib/rte_rib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/librte_rib/rte_rib.c b/lib/librte_rib/rte_rib.c index 2a370d7..6c29e1c 100644 --- a/lib/librte_rib/rte_rib.c +++ b/lib/librte_rib/rte_rib.c @@ -301,7 +301,7 @@ rte_rib_insert(struct rte_rib *rib, uint32_t ip, uint8_t depth) /* closest node found, new_node should be inserted in the middle */ common_depth = RTE_MIN(depth, (*tmp)->depth); common_prefix = ip ^ (*tmp)->ip; - d = __builtin_clz(common_prefix); + d = (common_prefix == 0) ? 32 : __builtin_clz(common_prefix); common_depth = RTE_MIN(d, common_depth); common_prefix = ip & rte_rib_depth_to_mask(common_depth); -- 2.7.4