netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [iproute2 1/2] ss: fix crash when skipping disabled header field
@ 2018-01-06 18:31 Antonio Quartulli
  2018-01-06 18:31 ` [iproute2 2/2] ss: fix NULL pointer access when parsing unix sockets with oldformat Antonio Quartulli
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Antonio Quartulli @ 2018-01-06 18:31 UTC (permalink / raw)
  To: netdev; +Cc: Antonio Quartulli, Stefano Brivio, Stephen Hemminger

When the first header field is disabled (i.e. when passing the -t
option), field_flush() is invoked with the `buffer` global variable
still zero'd.
However, in field_flush() we try to access buffer.cur->len
during variables initialization, thus leading to a SIGSEGV.

It's interesting to note that this bug appears only when the code
is compiled with -O0, because the compiler is smart
enough to immediately jump to the return statement if optimizations
are enabled and skip the faulty instruction.

Cc: Stefano Brivio <sbrivio@redhat.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
---
 misc/ss.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 1abf43d0..b35859dc 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1018,12 +1018,15 @@ static void print_right_spacing(struct column *f, int printed)
 /* Done with field: update buffer pointer, start new token after current one */
 static void field_flush(struct column *f)
 {
-	struct buf_chunk *chunk = buffer.tail;
-	unsigned int pad = buffer.cur->len % 2;
+	struct buf_chunk *chunk;
+	unsigned int pad;
 
 	if (f->disabled)
 		return;
 
+	chunk = buffer.tail;
+	pad = buffer.cur->len % 2;
+
 	if (buffer.cur->len > f->max_len)
 		f->max_len = buffer.cur->len;
 
-- 
2.15.1

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

end of thread, other threads:[~2018-01-09 16:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-06 18:31 [iproute2 1/2] ss: fix crash when skipping disabled header field Antonio Quartulli
2018-01-06 18:31 ` [iproute2 2/2] ss: fix NULL pointer access when parsing unix sockets with oldformat Antonio Quartulli
2018-01-06 19:28   ` Stefano Brivio
2018-01-06 19:51     ` Antonio Quartulli
2018-01-06 18:53 ` [iproute2 1/2] ss: fix crash when skipping disabled header field Stefano Brivio
2018-01-09 16:03 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).