public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jean-Philippe Brucker <jphilippe.brucker@gmail.com>
To: stephen@networkplumber.org
Cc: netdev@vger.kernel.org
Subject: [PATCH iproute2] ss: fix NULL dereference when rendering without header
Date: Sat,  3 Mar 2018 16:59:44 +0000	[thread overview]
Message-ID: <20180303165944.28102-1-jphilippe.brucker@gmail.com> (raw)

When ss is invoked with the no-header flag, if the query doesn't return
any result, render() is called with 'buffer' uninitialized. This
currently leads to a segfault. Ensure that buffer is initialized before
rendering.

The bug can be triggered with: ss -H sport = 100000

Signed-off-by: Jean-Philippe Brucker <jphilippe.brucker@gmail.com>
---
 misc/ss.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/misc/ss.c b/misc/ss.c
index e047f9c0..e087bef7 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1197,10 +1197,15 @@ newline:
 /* Render buffered output with spacing and delimiters, then free up buffers */
 static void render(int screen_width)
 {
-	struct buf_token *token = (struct buf_token *)buffer.head->data;
+	struct buf_token *token;
 	int printed, line_started = 0;
 	struct column *f;
 
+	if (!buffer.head)
+		return;
+
+	token = (struct buf_token *)buffer.head->data;
+
 	/* Ensure end alignment of last token, it wasn't necessarily flushed */
 	buffer.tail->end += buffer.cur->len % 2;
 
-- 
2.16.2

             reply	other threads:[~2018-03-03 17:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-03 16:59 Jean-Philippe Brucker [this message]
2018-03-03 17:35 ` [PATCH iproute2] ss: fix NULL dereference when rendering without header Stefano Brivio

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=20180303165944.28102-1-jphilippe.brucker@gmail.com \
    --to=jphilippe.brucker@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox