From patchwork Wed Oct 14 12:06:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 54910 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 4B83E23012 for ; Wed, 14 Oct 2015 12:09:14 +0000 (UTC) Received: by lbwr8 with SMTP id r8sf24811264lbw.0 for ; Wed, 14 Oct 2015 05:09:13 -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=krRsx7cuyr/5pcPlsekXVPp9MqP5AARQAgTHHsF6P3lOp1Gx7SLMJRU5zH2EwabY/F u2iZOt/WkCyDhJHg3Y+GCmJ8gAT1sUAnBqFEmf0YzHi+dhpE+jiml1Im/dLSHjqbFdbj lj2qpgiwU262/ZANWiqf7iS9Ad8Fq7h73SdBhUU44xlrcU0Ckf55ETcvXG+t+DPvArmw 4RkRLaaBiwu9sl/w0+WoolZenVqRcySUI77EKaf4iIZ8Nm91F3yDeOmXLKo4HEvDnjY2 0i3z8QNM8+KDJU/22Y/0gMkll07cBZh2oq4yawd60LgGzXg2fNzqZ5Y9qvLNa7sXLUIK njdg== X-Gm-Message-State: ALoCoQm0Pg9jBGE5iMHblH4JBOI3G7OLoY2PzD5CGIdVqkLpi5QLCX2ANykTKtsvqF+wFuWLec5d X-Received: by 10.112.54.197 with SMTP id l5mr675562lbp.21.1444824553281; Wed, 14 Oct 2015 05:09:13 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.152.199 with SMTP id a190ls31939lfe.62.gmail; Wed, 14 Oct 2015 05:09:13 -0700 (PDT) X-Received: by 10.25.165.84 with SMTP id o81mr934051lfe.80.1444824553144; Wed, 14 Oct 2015 05:09:13 -0700 (PDT) Received: from mail-lf0-f43.google.com (mail-lf0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id ru10si5329870lbb.110.2015.10.14.05.09.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2015 05:09:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by lffy185 with SMTP id y185so10174051lff.2 for ; Wed, 14 Oct 2015 05:09:13 -0700 (PDT) X-Received: by 10.25.28.81 with SMTP id c78mr920442lfc.29.1444824552894; Wed, 14 Oct 2015 05:09:12 -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.59.35 with SMTP id w3csp2692095lbq; Wed, 14 Oct 2015 05:09:12 -0700 (PDT) X-Received: by 10.140.96.53 with SMTP id j50mr3361102qge.100.1444824552002; Wed, 14 Oct 2015 05:09:12 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k185si1675865qhk.111.2015.10.14.05.09.10; Wed, 14 Oct 2015 05:09:11 -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 1F7D861BBF; Wed, 14 Oct 2015 12:09:10 +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 485F061C6F; Wed, 14 Oct 2015 12:06:58 +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 8164961BBF; Wed, 14 Oct 2015 12:06:48 +0000 (UTC) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by lists.linaro.org (Postfix) with ESMTPS id 45C1061A4D for ; Wed, 14 Oct 2015 12:06:42 +0000 (UTC) Received: by wicgb1 with SMTP id gb1so227874186wic.1 for ; Wed, 14 Oct 2015 05:06:41 -0700 (PDT) X-Received: by 10.180.184.201 with SMTP id ew9mr4338458wic.53.1444824401271; Wed, 14 Oct 2015 05:06:41 -0700 (PDT) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id gn9sm2638958wib.0.2015.10.14.05.06.40 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Oct 2015 05:06:40 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Wed, 14 Oct 2015 13:06:26 +0100 Message-Id: <1444824388-25708-3-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1444824388-25708-1-git-send-email-stuart.haslam@linaro.org> References: <1444824388-25708-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 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.215.43 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);