From patchwork Tue Dec 25 14:15:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Jarosch X-Patchwork-Id: 208108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id F23832C00AE for ; Wed, 26 Dec 2012 01:21:46 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753858Ab2LYOVo (ORCPT ); Tue, 25 Dec 2012 09:21:44 -0500 Received: from re04.intra2net.com ([82.165.46.26]:36983 "EHLO re04.intra2net.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753764Ab2LYOVo (ORCPT ); Tue, 25 Dec 2012 09:21:44 -0500 Received: from intranator.m.i2n (unknown [172.16.1.99]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by re04.intra2net.com (Postfix) with ESMTP id 3698C300D5; Tue, 25 Dec 2012 15:15:31 +0100 (CET) Received: from localhost (intranator.m.i2n [127.0.0.1]) by localhost (Postfix) with ESMTP id F010A2AC57; Tue, 25 Dec 2012 15:15:30 +0100 (CET) X-Virus-Scanned: by Intranator (www.intra2net.com) with AMaViS and F-Secure AntiVirus (fsavdb 2012-12-25_04) X-Spam-Status: X-Spam-Level: 0 Received: from pikkukde.a.i2n (unknown [192.168.12.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: smtp-auth-user) by intranator.m.i2n (Postfix) with ESMTPSA id 52D162AC54; Tue, 25 Dec 2012 15:15:28 +0100 (CET) Message-ID: <50D9B4FF.9000806@intra2net.com> Date: Tue, 25 Dec 2012 15:15:27 +0100 From: Thomas Jarosch User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Patrick McHardy CC: netfilter-devel@vger.kernel.org Subject: [libnl-nft PATCH] Fix out of bounds buffer access in rtnl_netem_set_delay_distribution() Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org sizeof(test_path) returns the array size and not the number of array elements. Detected by cppcheck Signed-off-by: Thomas Jarosch --- lib/route/sch/netem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/route/sch/netem.c b/lib/route/sch/netem.c index 18878a7..5894fd9 100644 --- a/lib/route/sch/netem.c +++ b/lib/route/sch/netem.c @@ -861,7 +861,7 @@ int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist return -NLE_NOMEM; FILE *f = NULL; - int i, n = 0; + int i = 0, n = 0; size_t len = 2048; char *line; char name[NAME_MAX]; @@ -873,11 +873,12 @@ int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist strcpy(dist_suffix, ""); /* Check several locations for the dist file */ - char *test_path[] = { "", "./", "/usr/lib/tc/", "/usr/local/lib/tc/" }; + char *test_path[] = { "", "./", "/usr/lib/tc/", "/usr/local/lib/tc/", NULL }; - for (i = 0; i < sizeof(test_path) && f == NULL; i++) { + while(f == NULL && test_path[i] != NULL) { snprintf(name, NAME_MAX, "%s%s%s", test_path[i], dist_type, dist_suffix); f = fopen(name, "r"); + ++i; } if ( f == NULL )