diff mbox series

[v1,1/3] package/liboping: add patch to fix gcc-8/gcc-9 snprintf truncation compile failure

Message ID 20200306201022.22382-1-ps.report@gmx.net
State Rejected
Headers show
Series [v1,1/3] package/liboping: add patch to fix gcc-8/gcc-9 snprintf truncation compile failure | expand

Commit Message

Peter Seiderer March 6, 2020, 8:10 p.m. UTC
Add patch from upstream merge request ([1]) to fix fix gcc-8/gcc-9 snprintf
truncation related compile failure (-Wall/-Werror), reported on the
mailing list ([2]).

Fixes:

  liboping.c: In function ‘ping_set_ttl’:
  liboping.c:207:9: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 242 [-Werror=format-truncation=]
    207 |    "%s: %s", function, message);
        |         ^~

[1] https://github.com/octo/liboping/pull/50
[2] http://lists.busybox.net/pipermail/buildroot/2020-March/275861.html

Reported-by: Maik Brenke <Maik.Brenke@continental-corporation.com>
Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
 ...d-snprintf-truncation-warning-wError.patch | 31 +++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 package/liboping/0002-Mitigated-snprintf-truncation-warning-wError.patch

Comments

Thomas Petazzoni March 7, 2020, 10:08 p.m. UTC | #1
Hello Peter,

On Fri,  6 Mar 2020 21:10:20 +0100
Peter Seiderer <ps.report@gmx.net> wrote:

> Add patch from upstream merge request ([1]) to fix fix gcc-8/gcc-9 snprintf
> truncation related compile failure (-Wall/-Werror), reported on the
> mailing list ([2]).
> 
> Fixes:
> 
>   liboping.c: In function ‘ping_set_ttl’:
>   liboping.c:207:9: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 242 [-Werror=format-truncation=]
>     207 |    "%s: %s", function, message);
>         |         ^~
> 
> [1] https://github.com/octo/liboping/pull/50
> [2] http://lists.busybox.net/pipermail/buildroot/2020-March/275861.html
> 
> Reported-by: Maik Brenke <Maik.Brenke@continental-corporation.com>
> Signed-off-by: Peter Seiderer <ps.report@gmx.net>

This build issue has happened once in the autobuilders:

  http://autobuild.buildroot.net/results/b12/b12d86388b495a96194e0bcbb5c19a4e35cbc53d/build-end.log

But liboping has been built successfully zillions of times:

  http://autobuild.buildroot.net/index.php?symbols%5BBR2_PACKAGE_LIBOPING%5D=y

Why is it that we don't see this build failure ?

Also, this build failure was reported at
https://github.com/octo/liboping/issues/38, and the upstream developer
says it has been fixed by
https://github.com/octo/liboping/commit/18ca43507b351f339ff23062541ee8d58e813a53,
which is different from your patch.

Could you clarify this ?

Thomas
Peter Seiderer March 7, 2020, 10:32 p.m. UTC | #2
Hello Thomas,

On Sat, 7 Mar 2020 23:08:52 +0100, Thomas Petazzoni <thomas.petazzoni@bootlin.com> wrote:

> Hello Peter,
> 
> On Fri,  6 Mar 2020 21:10:20 +0100
> Peter Seiderer <ps.report@gmx.net> wrote:
> 
> > Add patch from upstream merge request ([1]) to fix fix gcc-8/gcc-9 snprintf
> > truncation related compile failure (-Wall/-Werror), reported on the
> > mailing list ([2]).
> > 
> > Fixes:
> > 
> >   liboping.c: In function ‘ping_set_ttl’:
> >   liboping.c:207:9: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 242 [-Werror=format-truncation=]
> >     207 |    "%s: %s", function, message);
> >         |         ^~
> > 
> > [1] https://github.com/octo/liboping/pull/50
> > [2] http://lists.busybox.net/pipermail/buildroot/2020-March/275861.html
> > 
> > Reported-by: Maik Brenke <Maik.Brenke@continental-corporation.com>
> > Signed-off-by: Peter Seiderer <ps.report@gmx.net>  
> 
> This build issue has happened once in the autobuilders:
> 
>   http://autobuild.buildroot.net/results/b12/b12d86388b495a96194e0bcbb5c19a4e35cbc53d/build-end.log
> 
> But liboping has been built successfully zillions of times:
> 
>   http://autobuild.buildroot.net/index.php?symbols%5BBR2_PACKAGE_LIBOPING%5D=y
> 
> Why is it that we don't see this build failure ?

Don't know...but could reproduce it with the buildroot toolchain for
raspberry pi and gcc-9.2.0 and the original reporter used fs-toolchain-8.3-armv7ahf
(maybe a gcc-8.3 one)?

> 
> Also, this build failure was reported at
> https://github.com/octo/liboping/issues/38, and the upstream developer
> says it has been fixed by
> https://github.com/octo/liboping/commit/18ca43507b351f339ff23062541ee8d58e813a53,
> which is different from your patch.

This patch is part of buildroot since commit [3]...,
and fixes it at location line 1636ff, the new patch fixes a similar failure,
but not the same... at line 203ff...

> 
> Could you clarify this ?
> 

Maybe ;-)

Regards,
Peter

[3] https://git.buildroot.net/buildroot/commit/?id=8361c53eac06a8a96fd029e31ca7119e218e1e3e

> Thomas
Thomas Petazzoni Dec. 30, 2021, 3:11 p.m. UTC | #3
Hello Peter,

On Fri,  6 Mar 2020 21:10:20 +0100
Peter Seiderer <ps.report@gmx.net> wrote:

> Add patch from upstream merge request ([1]) to fix fix gcc-8/gcc-9 snprintf
> truncation related compile failure (-Wall/-Werror), reported on the
> mailing list ([2]).
> 
> Fixes:
> 
>   liboping.c: In function ‘ping_set_ttl’:
>   liboping.c:207:9: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 242 [-Werror=format-truncation=]
>     207 |    "%s: %s", function, message);
>         |         ^~
> 
> [1] https://github.com/octo/liboping/pull/50
> [2] http://lists.busybox.net/pipermail/buildroot/2020-March/275861.html
> 
> Reported-by: Maik Brenke <Maik.Brenke@continental-corporation.com>
> Signed-off-by: Peter Seiderer <ps.report@gmx.net>
> ---
>  ...d-snprintf-truncation-warning-wError.patch | 31 +++++++++++++++++++
>  1 file changed, 31 insertions(+)
>  create mode 100644 package/liboping/0002-Mitigated-snprintf-truncation-warning-wError.patch

So I'm sorry, but the problem still didn't occur. I've tried using gcc
8.x and 9.x toolchains, haven't been able to see, and neither were the
autobuilders.

So for now, I'll mark this patch as Rejected, but if you have a
reproducer, we can certainly reconsider this.

Best regards,

Thomas
Peter Seiderer Dec. 30, 2021, 11:14 p.m. UTC | #4
Hello Thomas,

On Thu, 30 Dec 2021 16:11:50 +0100, Thomas Petazzoni <thomas.petazzoni@bootlin.com> wrote:

> Hello Peter,
> 
> On Fri,  6 Mar 2020 21:10:20 +0100
> Peter Seiderer <ps.report@gmx.net> wrote:
> 
> > Add patch from upstream merge request ([1]) to fix fix gcc-8/gcc-9 snprintf
> > truncation related compile failure (-Wall/-Werror), reported on the
> > mailing list ([2]).
> > 
> > Fixes:
> > 
> >   liboping.c: In function ‘ping_set_ttl’:
> >   liboping.c:207:9: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 242 [-Werror=format-truncation=]
> >     207 |    "%s: %s", function, message);
> >         |         ^~
> > 
> > [1] https://github.com/octo/liboping/pull/50
> > [2] http://lists.busybox.net/pipermail/buildroot/2020-March/275861.html
> > 
> > Reported-by: Maik Brenke <Maik.Brenke@continental-corporation.com>
> > Signed-off-by: Peter Seiderer <ps.report@gmx.net>
> > ---
> >  ...d-snprintf-truncation-warning-wError.patch | 31 +++++++++++++++++++
> >  1 file changed, 31 insertions(+)
> >  create mode 100644 package/liboping/0002-Mitigated-snprintf-truncation-warning-wError.patch  
> 
> So I'm sorry, but the problem still didn't occur. I've tried using gcc
> 8.x and 9.x toolchains, haven't been able to see, and neither were the
> autobuilders.
> 
> So for now, I'll mark this patch as Rejected, but if you have a
> reproducer, we can certainly reconsider this.

Still reproducible with the following defconfig:

BR2_arm=y
BR2_arm1176jzf_s=y
BR2_OPTIMIZE_3=y
BR2_FORTIFY_SOURCE_NONE=y
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_GCC_VERSION_9_X=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_PACKAGE_LIBOPING=y

Regards,
Peter

> 
> Best regards,
> 
> Thomas
diff mbox series

Patch

diff --git a/package/liboping/0002-Mitigated-snprintf-truncation-warning-wError.patch b/package/liboping/0002-Mitigated-snprintf-truncation-warning-wError.patch
new file mode 100644
index 0000000000..929d25e22d
--- /dev/null
+++ b/package/liboping/0002-Mitigated-snprintf-truncation-warning-wError.patch
@@ -0,0 +1,31 @@ 
+From 215003b58c9214c4a3ff5ef44f361887cdbec348 Mon Sep 17 00:00:00 2001
+From: Guillaume Picquet <nelstaar@yahoo.fr>
+Date: Mon, 9 Sep 2019 17:30:47 +0200
+Subject: [PATCH] Mitigated snprintf truncation warning (-wError)
+
+[Upstream: https://github.com/octo/liboping/pull/50/commits/664414123a3fe89984abfa0917946c513bf47163]
+Signed-off-by: Peter Seiderer <ps.report@gmx.net>
+---
+ src/liboping.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/src/liboping.c b/src/liboping.c
+index a2dfa19..39b0041 100644
+--- a/src/liboping.c
++++ b/src/liboping.c
+@@ -203,9 +203,9 @@ static char *sstrerror (int errnum, char *buf, size_t buflen)
+ static void ping_set_error (pingobj_t *obj, const char *function,
+ 	       	const char *message)
+ {
+-	snprintf (obj->errmsg, sizeof (obj->errmsg),
+-			"%s: %s", function, message);
+-	obj->errmsg[sizeof (obj->errmsg) - 1] = 0;
++	if (snprintf (obj->errmsg, sizeof (obj->errmsg),
++			"%s: %s", function, message) >= sizeof (obj->errmsg))
++		obj->errmsg[sizeof (obj->errmsg) - 1] = 0;
+ }
+ 
+ static void ping_set_errno (pingobj_t *obj, int error_number)
+-- 
+2.25.1
+