From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id 678301B627 for ; Fri, 8 Feb 2019 17:21:48 +0100 (CET) Received: by mail-pf1-f195.google.com with SMTP id n74so625269pfi.9 for ; Fri, 08 Feb 2019 08:21:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pri4qYOyQZC2liEh0ldYUuBlgJcvd3cdEscFGg6U0P0=; b=aY3QSFjJXMsm/g3btn1rzm0VQQn/Fpih+jHAJxW5knog/qahweSI3Wv/un0d3yvneV hcto7HWIU1RL+pNuVVyeniAPvi86uM1GJfPVg14SnIVh0YHordS98pDXsQL+Bx7PeApH nO5o8D0EIzq/33MtCxQ/fUGxCQaStgxBdKQMAu5mMwqzLfV17yiGBTw38z552cbMO3N5 P0CnJp48Gfvd090rs97jUBzDDvklZgtMYSigFGFOA2zUSC2J3p3Xv88BT2x0lLgYQfXQ Si8R08v5hP6jQwgu5gkT9sHAH21WogYve6tEaLCyZI/fW8kQkiKkzWoc0vHxJ0hJp8/H 8zGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pri4qYOyQZC2liEh0ldYUuBlgJcvd3cdEscFGg6U0P0=; b=rwypZdgIJfajGX4APA6w4oVkiNi/VC7PFyurJF7Sw+sgEsPrF+Dczenb+unp/ucg82 SuLpfVwAUDU++RWtKrNEI4BIMyHyjx2xHkkiHlUD1O5ZpNnNu8GZqB8jnqVF5NNOTENS kTsFq7NhptxmUCrSBARu1LMfshvtIL0W6M82FNgZSOqgi5qIJ3DmUL9H8Y90kAWx1GT/ zRR+IKD+MOTZbme9lVydttkRtStnT+3sVwtNI48uasUpNXde2B9XRuNT4WkJqoD9dggT 8o2Kt+nOTTJXgNVi4XIYcC+U56rNHxci1f69yN3NvkA/fdUdUN/iPzDrtn+zcH+ziNbT Q1gg== X-Gm-Message-State: AHQUAuZdTEGuL2jGaMf2Iwcyo0iEVmyXT9SeecTX4YTOu0bhsrPqJGss xBXn5PN7OXy0n7CgcwjFxpxSAlDS1rw= X-Google-Smtp-Source: AHgI3IZApywNAhLu9aGXBcHZSWHOm68pvbCZdS+GPQyQqWdQ44ASriz6Uu8o4zetWkUjocwkstXNfg== X-Received: by 2002:a63:160d:: with SMTP id w13mr21642436pgl.43.1549642907429; Fri, 08 Feb 2019 08:21:47 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id m3sm4760181pfi.102.2019.02.08.08.21.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Feb 2019 08:21:47 -0800 (PST) Date: Fri, 8 Feb 2019 08:21:39 -0800 From: Stephen Hemminger To: Pallantla Poornima Cc: dev@dpdk.org, reshma.pattan@intel.com, ferruh.yigit@intel.com, stable@dpdk.org Message-ID: <20190208082139.57e8e060@hermes.lan> In-Reply-To: <1549632457-15892-1-git-send-email-pallantlax.poornima@intel.com> References: <1549632457-15892-1-git-send-email-pallantlax.poornima@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH] test: fix sprintf with snprintf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Feb 2019 16:21:48 -0000 On Fri, 8 Feb 2019 13:27:37 +0000 Pallantla Poornima wrote: > diff --git a/test/test/commands.c b/test/test/commands.c > index 94fbc310e..5aeb35498 100644 > --- a/test/test/commands.c > +++ b/test/test/commands.c > @@ -367,6 +367,8 @@ int commands_init(void) > struct test_command *t; > char *commands, *ptr; > int commands_len = 0; > + int total_written = 0; > + int count = 0; > > TAILQ_FOREACH(t, &commands_list, next) { > commands_len += strlen(t->command) + 1; > @@ -378,7 +380,10 @@ int commands_init(void) > > ptr = commands; > TAILQ_FOREACH(t, &commands_list, next) { > - ptr += sprintf(ptr, "%s#", t->command); > + count = snprintf(ptr, commands_len - total_written - 1, "%s#", > + t->command); > + ptr += count; > + total_written += count; You know snprintf is dangerous in this case as well. It returns the number of bytes that would have been written. That is why the linux kernel introduced scnprintf.