netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Henriksson <andreas@fatal.se>
To: stephen@networkplumber.org
Cc: netdev@vger.kernel.org
Subject: Bug#511720: [PATCH iproute2] ss: avoid passing negative numbers to malloc
Date: Tue, 12 Nov 2013 19:52:14 +0100	[thread overview]
Message-ID: <20131112185214.GA29913@amd64.fatal.se> (raw)

Example:

$ ss state established \( sport = :4060  or sport = :4061 or sport = :4062  or sport = :4063 or sport = :4064  or sport = :4065 or sport = :4066  or sport = :4067 \)  > /dev/null
Aborted

In the example above ssfilter_bytecompile(...) will return (int)136.
char l1 = 136; means -120 which will result in a negative number
being passed to malloc at misc/ss.c:913.

Simply declare l1 and l2 as intergers to avoid the char overflow.

This is one of the issues originally reported in http://bugs.debian.org/511720

Reported-by: Andreas Schuldei <andreas@debian.org>
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
---
 misc/ss.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/misc/ss.c b/misc/ss.c
index c0369f1..db3a3a4 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -907,7 +907,8 @@ static int ssfilter_bytecompile(struct ssfilter *f, char **bytecode)
 	}
 		case SSF_OR:
 	{
-		char *a1, *a2, *a, l1, l2;
+		char *a1, *a2, *a;
+		int l1, l2;
 		l1 = ssfilter_bytecompile(f->pred, &a1);
 		l2 = ssfilter_bytecompile(f->post, &a2);
 		if (!(a = malloc(l1+l2+4))) abort();
-- 
1.8.4.3

             reply	other threads:[~2013-11-12 18:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-12 18:52 Andreas Henriksson [this message]
2013-11-12 23:18 ` [PATCH iproute2] ss: avoid passing negative numbers to malloc Eric Dumazet
2013-11-13  8:46   ` [PATCH iproute2 v2] " Andreas Henriksson
2013-11-13 14:16     ` Eric Dumazet

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=20131112185214.GA29913@amd64.fatal.se \
    --to=andreas@fatal.se \
    --cc=511720@bugs.debian.org \
    --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;
as well as URLs for NNTP newsgroup(s).