From patchwork Wed Aug 5 15:26:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 51956 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id 2BDFE229FD for ; Wed, 5 Aug 2015 15:28:04 +0000 (UTC) Received: by lbbyj8 with SMTP id yj8sf14322472lbb.3 for ; Wed, 05 Aug 2015 08:28:03 -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=QlVaV+yeTaefNKAZd53y7J7UE6DypMPbHnSyMiWCDQ0=; b=LqB3DYyt4HPeXliTb0bbl5xYWs/l7HcZ4z0m9wzrwWS1AOa3qKvZL2jkPb8oNk/bcQ RGi5A1hpGU+60Kf6iSNIbKDBkge/TTWPBG7ud63dp2SdFkiD3Q9hKec7/qdqfW2cI9Rw 6a3rsya09OxhokL0QCWUeef3qNvsgJl7rKymUG8FdgZkQIeyjZHGjT2W74c98kLk23eV lqyvSYF7lz58JX8wSW1LDmLBW4Ir5vFhuhhhKaUW4iT+ESDiZ7uxRKUhiN7vUalI3q5x 0w1D8twort83+UVmVnQ1ZhmPceXtYSXgilNibVS2SBDdcG9cmwm7UYnOznH9iQ+jT8wS g2rA== X-Gm-Message-State: ALoCoQmA8/x7YUp/tbZcoAUc4cdvOix4bX94xesXZ9sJsCh37Fz5mIxp96zQGiu+KHIxdPdgp54+ X-Received: by 10.180.160.133 with SMTP id xk5mr1619418wib.1.1438788483052; Wed, 05 Aug 2015 08:28:03 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.204 with SMTP id ba12ls207549lab.62.gmail; Wed, 05 Aug 2015 08:28:02 -0700 (PDT) X-Received: by 10.152.25.169 with SMTP id d9mr9975011lag.80.1438788482758; Wed, 05 Aug 2015 08:28:02 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id kn15si2360466lbb.85.2015.08.05.08.28.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Aug 2015 08:28:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbbvv8 with SMTP id vv8so24090271lbb.1 for ; Wed, 05 Aug 2015 08:28:02 -0700 (PDT) X-Received: by 10.152.22.99 with SMTP id c3mr10019599laf.32.1438788482651; Wed, 05 Aug 2015 08:28:02 -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.7.198 with SMTP id l6csp435037lba; Wed, 5 Aug 2015 08:28:01 -0700 (PDT) X-Received: by 10.50.154.10 with SMTP id vk10mr10917471igb.39.1438788477752; Wed, 05 Aug 2015 08:27:57 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v15si2717586iov.63.2015.08.05.08.27.55; Wed, 05 Aug 2015 08:27: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 5378361FD8; Wed, 5 Aug 2015 15:27:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal 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 ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id A318361FBC; Wed, 5 Aug 2015 15:27:20 +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 D60D661FA9; Wed, 5 Aug 2015 15:26:57 +0000 (UTC) Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by lists.linaro.org (Postfix) with ESMTPS id 41AFD61CCF for ; Wed, 5 Aug 2015 15:26:56 +0000 (UTC) Received: by wicne3 with SMTP id ne3so9582409wic.1 for ; Wed, 05 Aug 2015 08:26:55 -0700 (PDT) X-Received: by 10.180.86.129 with SMTP id p1mr10964803wiz.71.1438788415519; Wed, 05 Aug 2015 08:26:55 -0700 (PDT) Received: from e106441.cambridge.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id y13sm4637638wjq.26.2015.08.05.08.26.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Aug 2015 08:26:54 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Wed, 5 Aug 2015 16:26:40 +0100 Message-Id: <1438788402-9250-2-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1438788402-9250-1-git-send-email-stuart.haslam@linaro.org> References: <1438788402-9250-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 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.180 as permitted sender) smtp.mail=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 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index b55a6f9..bed254d 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -310,25 +310,25 @@ 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); 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"); + strcpy(stats[args->policy_count].queue_name, queue_name); odp_atomic_init_u64(&stats[args->policy_count].packet_count, 0); args->policy_count++; } @@ -343,7 +343,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, @@ -354,7 +355,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);