From patchwork Mon Jan 30 14:35:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 92872 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1464437qgi; Mon, 30 Jan 2017 06:35:42 -0800 (PST) X-Received: by 10.200.56.4 with SMTP id q4mr21983798qtb.73.1485786942565; Mon, 30 Jan 2017 06:35:42 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p39si9659293qkh.112.2017.01.30.06.35.42; Mon, 30 Jan 2017 06:35:42 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2F42260796; Mon, 30 Jan 2017 14:35:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 9708660644; Mon, 30 Jan 2017 14:35:38 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id A91E360645; Mon, 30 Jan 2017 14:35:35 +0000 (UTC) Received: from mail-ot0-f170.google.com (mail-ot0-f170.google.com [74.125.82.170]) by lists.linaro.org (Postfix) with ESMTPS id A4E406063F for ; Mon, 30 Jan 2017 14:35:34 +0000 (UTC) Received: by mail-ot0-f170.google.com with SMTP id 65so243423708otq.2 for ; Mon, 30 Jan 2017 06:35:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yPRqxfa1TKhK2yi5gohcbuekHT8RLilAB9GULKBwL7k=; b=XNEFY9XQTBjle/yRGRG+6Bj6lcFCZW2rW7ET8/0iQD4pfqBn7EgohfWr06K9bNFMX4 532gjePMXChcmLYx+TJGz99HkS+5i/CoaN0G8qj/YSQ8S2DnoAriJZzSLUYjGpVrVTjT m0ji22dxJrYGNAVys8EuMqt0lokQZVlngrNreKC+tET86Bt4CvpAOEYcpGYNuFRDqso1 OoysaMCZsZKdkBSXwu5BkiA5mO6cotYMrL2jxb7uK4VCDPrNZYusTNL1M0QDBiAPHfbQ UiAvJIF5LSRSK9YV+nJl5uq1pWYk0yafWA+BJd+JXh8DNUdTqbuQxPtvnExUAW7TVV+k 10Zg== X-Gm-Message-State: AIkVDXIcDmnRT6SJzrdzDOnhdGbIgO6k/PipNtLaVheCv1aEeMy8JbpD1CqcncU3mkpNR1BvDJg= X-Received: by 10.157.11.137 with SMTP id 9mr9798518oth.14.1485786934150; Mon, 30 Jan 2017 06:35:34 -0800 (PST) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id v31sm7080865ota.26.2017.01.30.06.35.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 06:35:33 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 30 Jan 2017 08:35:30 -0600 Message-Id: <20170130143530.14944-1-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.9.3 Subject: [lng-odp] [PATCH] helper: iplookuptable: avoid potential null pointer dereferences X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Resolve Bug https://bugs.linaro.org/show_bug.cgi?id=2862 by checking pointer validity before dereferencing. Signed-off-by: Bill Fischofer --- helper/iplookuptable.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) -- 2.9.3 Reviewed-by: Mike Holmes diff --git a/helper/iplookuptable.c b/helper/iplookuptable.c index aaebea3..845125b 100644 --- a/helper/iplookuptable.c +++ b/helper/iplookuptable.c @@ -666,12 +666,14 @@ odph_iplookup_table_put_value(odph_table_t tbl, void *key, void *value) odph_iplookup_table_impl *impl = (void *)tbl; odph_iplookup_prefix_t *prefix = (odph_iplookup_prefix_t *)key; prefix_entry_t *l1e = NULL; - odp_buffer_t nexthop = *((odp_buffer_t *)value); + odp_buffer_t nexthop; int ret = 0; if ((tbl == NULL) || (key == NULL) || (value == NULL)) return -1; + nexthop = *((odp_buffer_t *)value); + if (prefix->cidr == 0) return -1; prefix->ip = prefix->ip & (0xffffffff << (IP_LENGTH - prefix->cidr)); @@ -708,13 +710,16 @@ int odph_iplookup_table_get_value(odph_table_t tbl, void *key, uint32_t buffer_size ODP_UNUSED) { odph_iplookup_table_impl *impl = (void *)tbl; - uint32_t ip = *((uint32_t *)key); - prefix_entry_t *entry = &impl->l1e[ip >> 16]; + uint32_t ip; + prefix_entry_t *entry; odp_buffer_t *buff = (odp_buffer_t *)buffer; if ((tbl == NULL) || (key == NULL) || (buffer == NULL)) return -EINVAL; + ip = *((uint32_t *)key); + entry = &impl->l1e[ip >> 16]; + if (entry == NULL) { ODPH_DBG("failed to get L1 entry.\n"); return -1; @@ -881,13 +886,16 @@ odph_iplookup_table_remove_value(odph_table_t tbl, void *key) { odph_iplookup_table_impl *impl = (void *)tbl; odph_iplookup_prefix_t *prefix = (odph_iplookup_prefix_t *)key; - uint32_t ip = prefix->ip; - uint8_t cidr = prefix->cidr; + uint32_t ip; + uint8_t cidr; if ((tbl == NULL) || (key == NULL)) return -EINVAL; - if (!prefix->cidr) + ip = prefix->ip; + cidr = prefix->cidr; + + if (cidr == 0) return -EINVAL; prefix_entry_t *entry = &impl->l1e[ip >> 16];