From patchwork Thu Dec 3 18:49:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 57666 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp102488lbb; Thu, 3 Dec 2015 10:50:11 -0800 (PST) X-Received: by 10.140.93.52 with SMTP id c49mr12979586qge.101.1449168611846; Thu, 03 Dec 2015 10:50:11 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c2si2934645qge.105.2015.12.03.10.50.11; Thu, 03 Dec 2015 10:50:11 -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; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 4456862CEC; Thu, 3 Dec 2015 18:50:11 +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=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID,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 50AEB62CE9; Thu, 3 Dec 2015 18:50:07 +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 E679762CEA; Thu, 3 Dec 2015 18:50:05 +0000 (UTC) Received: from mail-qg0-f47.google.com (mail-qg0-f47.google.com [209.85.192.47]) by lists.linaro.org (Postfix) with ESMTPS id 0DD6E62CE0 for ; Thu, 3 Dec 2015 18:50:05 +0000 (UTC) Received: by qgcc31 with SMTP id c31so68250101qgc.3 for ; Thu, 03 Dec 2015 10:50:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=TIGdPpeWShFWnQHazhtCYH7nhv0Maz9UkNx33rYQ3jM=; b=0CJMp4WwdMW617IOgiTuMp4Q5daAcDAKqQ80g81Uw8fcXeEHQYSBBMZJpjwrFQ3xXq Ik5Y6w8CAjIUBCgKiWMKiFalOGi68WMZXyAoQRVawhA6MwHGXXCxDGyepIl24QHXAKiJ 5RLoQPXv2vuzJ3daqIhwfNFcjTNYio7N9ndPFtnVdLVAUpNz4tRZ2A9mw95o/Th01NRl vXuQGKlUAtQ1mGOkQSTYT00b8k4OiGEpdfPvvHKz2YqrTi+zT5HYPy5xyArWSPc++Xzv EW7oF/v32QQ397xZ3llKVZXUCsH1UxsZa1hSObthMtLuuiF9q+Ya9q71n+8IK6rZzRU6 wK/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TIGdPpeWShFWnQHazhtCYH7nhv0Maz9UkNx33rYQ3jM=; b=ZsakhjRnLlitmh35sYf0Rr1uzHhOVZZ/L+PD+W0s5BIdVBN+Y1/6yyi8l+eFLX0fSz VPjSpHfiLL+A+ns20k4O/8xNc6ASGtUcrEUhyXbUC8vExaIt8VgrfjsQej/gytqdCN2o TXnS9utEQUnGNFQ6QGoi1VHIFUxHbKqA9DAK+T1v0R2/lkGwc6YHjXDg7GWU/bcUtP56 O3Cz3P25bxsto2kvNp1lgMXCPAsUhVYvJDXcZ9tKg8wdcsErhvI1O4KZNQrIvzy6SjgS z+/+qpvr85hxD9CUOtQm57LYDSYi/fsBSwFxdJBrzUI0MaW+q50CI2TDv1i6t+M/4N4h E/rw== X-Gm-Message-State: ALoCoQkEuszE6Nwc0K/izkU4w0wQnBA9Ld8k3yyc3/rdPfjYiUqXEK1JJ0gbxP/nZcrRrdAnLp6S X-Received: by 10.140.236.211 with SMTP id h202mr13294638qhc.7.1449168604716; Thu, 03 Dec 2015 10:50:04 -0800 (PST) Received: from localhost.localdomain (c-98-221-136-245.hsd1.nj.comcast.net. [98.221.136.245]) by smtp.gmail.com with ESMTPSA id e134sm3800004qhc.49.2015.12.03.10.50.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Dec 2015 10:50:04 -0800 (PST) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Thu, 3 Dec 2015 13:49:57 -0500 Message-Id: <1449168597-438-1-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.5.0 X-Topics: patch Subject: [lng-odp] [PATCH] helper: fix strncpy in table support 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Fixes Bug 1905 - CID 154167: Calling strncpy with a maximum size argument of ODP_TABLE_NAME_LEN bytes on destination array tbl->name of size ODP_TABLE_NAME_LEN bytes might leave the destination string unterminated if the copied string is also of the maximum size ODP_TABLE_NAME_LEN. Make the copy leave one char for the null terminator. Signed-off-by: Mike Holmes Reviewed-by: Bill Fischofer --- helper/hashtable.c | 2 +- helper/lineartable.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/helper/hashtable.c b/helper/hashtable.c index 1121beb..e0f562e 100644 --- a/helper/hashtable.c +++ b/helper/hashtable.c @@ -92,7 +92,7 @@ odph_table_t odph_hash_table_create(const char *name, uint32_t capacity, memset(tbl, 0, capacity << 20); tbl->init_cap = capacity << 20; - strncpy(tbl->name, name, ODPH_TABLE_NAME_LEN); + strncpy(tbl->name, name, ODPH_TABLE_NAME_LEN - 1); tbl->key_size = key_size; tbl->value_size = value_size; diff --git a/helper/lineartable.c b/helper/lineartable.c index b0759f9..68d9350 100644 --- a/helper/lineartable.c +++ b/helper/lineartable.c @@ -73,7 +73,7 @@ odph_table_t odph_linear_table_create(const char *name, uint32_t capacity, tbl->init_cap = capacity < 20; - strncpy(tbl->name, name, ODPH_TABLE_NAME_LEN); + strncpy(tbl->name, name, ODPH_TABLE_NAME_LEN - 1); /* for linear table, the key is just the index, without confict * so we just need to record the value content