All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
To: Stephen Hemminger
	<stephen-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>
Cc: dev-VfR2kkLFssw@public.gmane.org
Subject: [PATCH 3/3] fix incorrect snprintf usage
Date: Tue, 24 Jun 2014 09:05:30 -0700	[thread overview]
Message-ID: <20140624090530.56318f6f@nehalam.linuxnetplumber.net> (raw)
In-Reply-To: <20140624090253.140206a7-We1ePj4FEcvRI77zikRAJc56i+j3xesD0e7PPNI6Mm0@public.gmane.org>

Now that snprintf is used, Gcc finds more uses of unsafe arguments.
Fix where found. These may have already been fixed by
other patches on the mailing list.

Signed-off-by: Stephen Hemminger <stephen-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org>


--- a/lib/librte_kni/rte_kni.c	2014-06-24 08:48:55.758031238 -0700
+++ b/lib/librte_kni/rte_kni.c	2014-06-24 08:48:55.754031210 -0700
@@ -158,7 +158,7 @@ rte_kni_alloc(struct rte_mempool *pktmbu
 		}
 	}
 
-	snprintf(intf_name, RTE_KNI_NAMESIZE, conf->name);
+	snprintf(intf_name, RTE_KNI_NAMESIZE, "%s", conf->name);
 	snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "KNI_INFO_%s", intf_name);
 	mz = kni_memzone_reserve(mz_name, sizeof(struct rte_kni),
 				SOCKET_ID_ANY, 0);
@@ -184,8 +184,8 @@ rte_kni_alloc(struct rte_mempool *pktmbu
 	dev_info.group_id = conf->group_id;
 	dev_info.mbuf_size = conf->mbuf_size;
 
-	snprintf(ctx->name, RTE_KNI_NAMESIZE, intf_name);
-	snprintf(dev_info.name, RTE_KNI_NAMESIZE, intf_name);
+	snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name);
+	snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name);
 
 	RTE_LOG(INFO, KNI, "pci: %02x:%02x:%02x \t %02x:%02x\n",
 		dev_info.bus, dev_info.devid, dev_info.function,
@@ -291,7 +291,7 @@ rte_kni_release(struct rte_kni *kni)
 	if (!kni || !kni->in_use)
 		return -1;
 
-	snprintf(dev_info.name, sizeof(dev_info.name), kni->name);
+	snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
 	if (ioctl(kni_fd, RTE_KNI_IOCTL_RELEASE, &dev_info) < 0) {
 		RTE_LOG(ERR, KNI, "Fail to release kni device\n");
 		return -1;
--- a/app/test/test_cmdline_etheraddr.c	2014-06-24 08:35:31.820146456 -0700
+++ b/app/test/test_cmdline_etheraddr.c	2014-06-24 08:54:35.396486084 -0700
@@ -147,7 +147,7 @@ test_parse_etheraddr_invalid_param(void)
 
 	/* copy string to buffer */
 	snprintf(buf, sizeof(buf), "%s",
-			ether_addr_valid_strs[0]);
+		 ether_addr_valid_strs[0].str);
 
 	ret = cmdline_parse_etheraddr(NULL, buf, NULL);
 	if (ret == -1) {
--- a/app/test/test_eal_flags.c	2014-06-24 08:35:31.820146456 -0700
+++ b/app/test/test_eal_flags.c	2014-06-24 08:53:16.623916364 -0700
@@ -268,7 +268,7 @@ get_current_prefix(char * prefix, int si
 
 	/* copy string all the way from second char up to start of _config */
 	snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+		 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")), &buf[1]);
 
 	return prefix;
 }
--- a/app/test/test_mp_secondary.c	2014-06-24 08:35:31.820146456 -0700
+++ b/app/test/test_mp_secondary.c	2014-06-24 08:50:27.706700011 -0700
@@ -103,7 +103,7 @@ get_current_prefix(char * prefix, int si
 
 	/* copy string all the way from second char up to start of _config */
 	snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+		 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")), &buf[1]);
 
 	return prefix;
 }

  parent reply	other threads:[~2014-06-24 16:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-24 16:02 [PATCH 1/3] stringfns: remove rte_snprintf Stephen Hemminger
     [not found] ` <20140624090253.140206a7-We1ePj4FEcvRI77zikRAJc56i+j3xesD0e7PPNI6Mm0@public.gmane.org>
2014-06-24 16:03   ` [PATCH 2/3] test: remove no longer valid tests Stephen Hemminger
2014-06-24 16:05   ` Stephen Hemminger [this message]
2014-06-24 17:39   ` [PATCH 1/3] stringfns: remove rte_snprintf Richardson, Bruce
     [not found]     ` <59AF69C657FD0841A61C55336867B5B02CEE3359-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-06-24 17:54       ` Stephen Hemminger
     [not found]         ` <20140624105427.166c21bf-We1ePj4FEcvRI77zikRAJc56i+j3xesD0e7PPNI6Mm0@public.gmane.org>
2014-06-24 18:00           ` Richardson, Bruce
     [not found]             ` <59AF69C657FD0841A61C55336867B5B02CEE345B-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-06-25  7:55               ` Olivier MATZ
2014-06-25  8:33       ` Thomas Monjalon
2014-06-26 15:09         ` Richardson, Bruce
     [not found]           ` <59AF69C657FD0841A61C55336867B5B02CEF87D2-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-06-26 16:20             ` Aaron Campbell
     [not found]               ` <5590E373-EC37-4544-A983-52156CFA81E2-rd7evPjynkNeoWH0uzbU5w@public.gmane.org>
2014-06-27  0:37                 ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140624090530.56318f6f@nehalam.linuxnetplumber.net \
    --to=stephen-otpzqlsittunbdjkjebofr2eb7je58tq@public.gmane.org \
    --cc=dev-VfR2kkLFssw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.