From patchwork Fri Sep 4 13:20:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 53090 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id A60FD2159E for ; Fri, 4 Sep 2015 13:22:59 +0000 (UTC) Received: by laeb10 with SMTP id b10sf7554364lae.1 for ; Fri, 04 Sep 2015 06:22:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=7C/NyhWu66+Khg2iLezKeEaX1ebrtoDlYd95fxCUG50=; b=ZXNnqsahlxjsmcO9nxEnDlSq+WQOZMHVouFR53yUOb7K5hNRk3Xp72oJE6j89aAOyz xBdFaic9yJ8VFGX+78g2MtKrIO5DvosvrU5L8vra21wCqQVAb0d+T31bP5sEF9F3XRhe NyQZFosScavo6dACwoc7QKhQ2Oy1BEQ37/oZdtqkHrsd2XHgBB4KhRaB5DpB/RiRU/zA SvRpWpusV8NNlOoxeS8qiAyAoI7UL4bMv8HAY3jONK+0AnnRkLhVnW3JMIqwJ9Hp7LCL qp2d6u2KOmoYStgGaTKVpfYdkDXQivtXFcs964YU4n57ggQNYDUhLjqIS+C1T+p9s1KL wEOQ== X-Gm-Message-State: ALoCoQl0s1C2ZLI+tTv1EzHJ5PMXFNITB1qqLcKMNLJ/IiurqOKgF3DlmVXIlhBV5qReDt7Kxsgj X-Received: by 10.180.79.66 with SMTP id h2mr1087189wix.3.1441372978612; Fri, 04 Sep 2015 06:22:58 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.164 with SMTP id ld4ls344946lab.62.gmail; Fri, 04 Sep 2015 06:22:58 -0700 (PDT) X-Received: by 10.152.30.98 with SMTP id r2mr1679857lah.14.1441372978319; Fri, 04 Sep 2015 06:22:58 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id v4si2314490lav.48.2015.09.04.06.22.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Sep 2015 06:22:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbcao8 with SMTP id ao8so11126083lbc.3 for ; Fri, 04 Sep 2015 06:22:58 -0700 (PDT) X-Received: by 10.112.168.100 with SMTP id zv4mr3631220lbb.117.1441372978222; Fri, 04 Sep 2015 06:22:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.164.42 with SMTP id yn10csp1969739lbb; Fri, 4 Sep 2015 06:22:57 -0700 (PDT) X-Received: by 10.140.202.210 with SMTP id x201mr5487929qha.0.1441372977041; Fri, 04 Sep 2015 06:22:57 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b68si2750301qgf.92.2015.09.04.06.22.56; Fri, 04 Sep 2015 06:22:57 -0700 (PDT) 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; Received: by lists.linaro.org (Postfix, from userid 109) id 2525061A3D; Fri, 4 Sep 2015 13:22:56 +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.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 686B8619C7; Fri, 4 Sep 2015 13:22:21 +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 CF45161A01; Fri, 4 Sep 2015 13:22:15 +0000 (UTC) Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) by lists.linaro.org (Postfix) with ESMTPS id D4AD5619C7 for ; Fri, 4 Sep 2015 13:22:14 +0000 (UTC) Received: by wiclk2 with SMTP id lk2so17893321wic.1 for ; Fri, 04 Sep 2015 06:22:14 -0700 (PDT) X-Received: by 10.180.149.208 with SMTP id uc16mr7200457wib.7.1441372934148; Fri, 04 Sep 2015 06:22:14 -0700 (PDT) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id gt10sm4155421wib.20.2015.09.04.06.22.13 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Sep 2015 06:22:13 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Fri, 4 Sep 2015 14:20:27 +0100 Message-Id: <1441372829-12886-3-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1441372829-12886-1-git-send-email-stuart.haslam@linaro.org> References: <1441372829-12886-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 2/4] example: classifier: fix potential buffer overflow X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stuart.haslam@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 cos_name will overflow if args->if_name is long, so change the sprintf to snprintf. For consistency the other uses of sprintf are also removed. Signed-off-by: Stuart Haslam --- example/classifier/odp_classifier.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index 685f335..e634c9b 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -317,26 +317,28 @@ static void configure_default_queue(odp_pktio_t pktio, appl_args_t *args) odp_queue_param_t qparam; odp_cos_t cos_default; char cos_name[ODP_COS_NAME_LEN]; - char queue_name[ODP_QUEUE_NAME_LEN]; + const char *queue_name = "DefaultQueue"; odp_queue_t queue_default; global_statistics *stats = args->stats; - sprintf(cos_name, "Default%s", args->if_name); + + snprintf(cos_name, sizeof(cos_name), "Default%s", args->if_name); cos_default = odp_cos_create(cos_name); odp_queue_param_init(&qparam); qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; qparam.sched.sync = ODP_SCHED_SYNC_NONE; qparam.sched.group = ODP_SCHED_GROUP_ALL; - sprintf(queue_name, "%s", "DefaultQueue"); queue_default = odp_queue_create(queue_name, - ODP_QUEUE_TYPE_SCHED, &qparam); + ODP_QUEUE_TYPE_SCHED, &qparam); odp_cos_set_queue(cos_default, queue_default); odp_pktio_default_cos_set(pktio, cos_default); stats[args->policy_count].cos = cos_default; /* add default queue to global stats */ stats[args->policy_count].queue = queue_default; - strcpy(stats[args->policy_count].queue_name, "DefaultQueue"); + snprintf(stats[args->policy_count].queue_name, + sizeof(stats[args->policy_count].queue_name), + "%s", queue_name); odp_atomic_init_u64(&stats[args->policy_count].packet_count, 0); args->policy_count++; } @@ -351,7 +353,8 @@ static void configure_cos_queue(odp_pktio_t pktio, appl_args_t *args) for (i = 0; i < args->policy_count; i++) { stats = &args->stats[i]; - sprintf(cos_name, "CoS%s", stats->queue_name); + snprintf(cos_name, sizeof(cos_name), "CoS%s", + stats->queue_name); stats->cos = odp_cos_create(cos_name); stats->pmr = odp_pmr_create(stats->rule.term, @@ -362,7 +365,8 @@ static void configure_cos_queue(odp_pktio_t pktio, appl_args_t *args) qparam.sched.sync = ODP_SCHED_SYNC_NONE; qparam.sched.group = ODP_SCHED_GROUP_ALL; - sprintf(queue_name, "%s%d", args->stats[i].queue_name, i); + snprintf(queue_name, sizeof(queue_name), "%s%d", + args->stats[i].queue_name, i); stats->queue = odp_queue_create(queue_name, ODP_QUEUE_TYPE_SCHED, &qparam);