All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] tst_net_vars.c: Fix size for IPv4 address buffer
@ 2019-05-09 16:41 Petr Vorel
  2019-05-09 16:41 ` [LTP] [PATCH 2/2] tst_net_vars.c: Enlarge buffer to fix format overflow warnings Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2019-05-09 16:41 UTC (permalink / raw)
  To: ltp

INET_ADDRSTRLEN is maximum IPv4 length including the terminating null
byte, thus removing + 1 from buffer size.

Fixes: d18e135d0 ("network: Add tools for setup IP related environment
variables")

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/tst_net_vars.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/testcases/lib/tst_net_vars.c b/testcases/lib/tst_net_vars.c
index fc63f1395..da9a4e64c 100644
--- a/testcases/lib/tst_net_vars.c
+++ b/testcases/lib/tst_net_vars.c
@@ -153,7 +153,7 @@ static int is_in_subnet_ipv6(const struct in6_addr *network,
  */
 static char *get_ipv4_netmask(unsigned int prefix)
 {
-	char buf[INET_ADDRSTRLEN + 1];
+	char buf[INET_ADDRSTRLEN];
 	struct in_addr mask = prefix2mask(prefix);
 
 	if (prefix > MAX_IPV4_PREFIX)
@@ -200,7 +200,7 @@ static char *get_ipv4_broadcast(struct in_addr ip, unsigned int prefix)
 {
 	struct in_addr mask = prefix2mask(prefix);
 	struct in_addr broadcast;
-	char buf[INET_ADDRSTRLEN + 1];
+	char buf[INET_ADDRSTRLEN];
 
 	memset(&broadcast, 0, sizeof(broadcast));
 	broadcast.s_addr = (ip.s_addr & mask.s_addr) | ~mask.s_addr;
@@ -471,7 +471,7 @@ static void check_prefix_range(unsigned int prefix, int is_ipv6, int is_lhost)
 
 static char *get_ipv4_network(int ip, unsigned int prefix)
 {
-	char buf[INET_ADDRSTRLEN + 1];
+	char buf[INET_ADDRSTRLEN];
 	char *p_buf = buf;
 	unsigned char byte;
 	unsigned int i;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH 2/2] tst_net_vars.c: Enlarge buffer to fix format overflow warnings
  2019-05-09 16:41 [LTP] [PATCH 1/2] tst_net_vars.c: Fix size for IPv4 address buffer Petr Vorel
@ 2019-05-09 16:41 ` Petr Vorel
  2019-05-20 15:34   ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2019-05-09 16:41 UTC (permalink / raw)
  To: ltp

tst_net_vars.c:230:18: warning: ‘.0.0’ directive writing 4 bytes into a region of size between 1 and 128 [-Wformat-overflow=]
  sprintf(buf, "%s.0.0", net_unused);
                  ^~~~
In file included from /usr/include/stdio.h:867,
                 from tst_net_vars.c:26:
/usr/include/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 5 and 132 bytes into a destination of size 128

tst_net_vars.c:294:18: warning: ‘::’ directive writing 2 bytes into a region of size between 1 and 128 [-Wformat-overflow=]
  sprintf(buf, "%s::", net_unused);
                  ^~
In file included from /usr/include/stdio.h:867,
                 from tst_net_vars.c:26:
/usr/include/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 3 and 130 bytes into a destination of size 128

Fixes: d18e135d0 ("network: Add tools for setup IP related environment
variables")

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/tst_net_vars.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/testcases/lib/tst_net_vars.c b/testcases/lib/tst_net_vars.c
index da9a4e64c..43cd92bcf 100644
--- a/testcases/lib/tst_net_vars.c
+++ b/testcases/lib/tst_net_vars.c
@@ -220,7 +220,7 @@ static char *get_ipv4_net16_unused(const struct in_addr *ip,
 	unsigned int prefix)
 {
 	struct in_addr mask, network;
-	char buf[128], net_unused[128];
+	char buf[132], net_unused[128];
 
 	mask = prefix2mask(prefix);
 	network = calc_network(ip, &mask);
@@ -274,7 +274,7 @@ static char *get_ipv6_net32_unused(const struct in6_addr *ip6,
 {
 	int i, j;
 	struct in6_addr mask, network;
-	char buf[128], net_unused[128];
+	char buf[130], net_unused[128];
 
 	memset(&mask, 0x0, sizeof(mask));
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH 2/2] tst_net_vars.c: Enlarge buffer to fix format overflow warnings
  2019-05-09 16:41 ` [LTP] [PATCH 2/2] tst_net_vars.c: Enlarge buffer to fix format overflow warnings Petr Vorel
@ 2019-05-20 15:34   ` Petr Vorel
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2019-05-20 15:34 UTC (permalink / raw)
  To: ltp

Hi,

> tst_net_vars.c:230:18: warning: ‘.0.0’ directive writing 4 bytes into a region of size between 1 and 128 [-Wformat-overflow=]
>   sprintf(buf, "%s.0.0", net_unused);
>                   ^~~~
> In file included from /usr/include/stdio.h:867,
>                  from tst_net_vars.c:26:
> /usr/include/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 5 and 132 bytes into a destination of size 128

> tst_net_vars.c:294:18: warning: ‘::’ directive writing 2 bytes into a region of size between 1 and 128 [-Wformat-overflow=]
>   sprintf(buf, "%s::", net_unused);
>                   ^~
> In file included from /usr/include/stdio.h:867,
>                  from tst_net_vars.c:26:
> /usr/include/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 3 and 130 bytes into a destination of size 128

> Fixes: d18e135d0 ("network: Add tools for setup IP related environment
> variables")

> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/tst_net_vars.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Both commits pushed.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-20 15:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-09 16:41 [LTP] [PATCH 1/2] tst_net_vars.c: Fix size for IPv4 address buffer Petr Vorel
2019-05-09 16:41 ` [LTP] [PATCH 2/2] tst_net_vars.c: Enlarge buffer to fix format overflow warnings Petr Vorel
2019-05-20 15:34   ` Petr Vorel

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.