netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Henriksson <andreas@fatal.se>
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: netdev@vger.kernel.org, Andrew France <andrew@avito.co.uk>,
	488430@bugs.debian.org
Subject: Re: [Fwd: Bug#488430: iproute: lnstat causes segmentation fault]
Date: Mon, 30 Jun 2008 20:20:41 +0200	[thread overview]
Message-ID: <1214850041.16171.53.camel@amd64.fatal.se> (raw)
In-Reply-To: <20080630103625.7e718a93@extreme>

On mån, 2008-06-30 at 10:36 -0700, Stephen Hemminger wrote:
> The problem is that MAX_FIELDS is 64, but lnstat is finding 71 fields.
> This causes a array out of range problem.
> 
> Just bump MAX_FIELDS to 128

Oh, stupid me to not catch that when I was thinking it used un-allocated
memory and all...
Here's a patch that prevents the overflow and throws a warning instead.


diff --git a/misc/lnstat.c b/misc/lnstat.c
index b56598a..5a0c349 100644
--- a/misc/lnstat.c
+++ b/misc/lnstat.c
@@ -121,6 +121,10 @@ static int map_field_params(struct lnstat_file *lnstat_files,
 				if (!fps->params[j].print.width)
 					fps->params[j].print.width =
 							FIELD_WIDTH_DEFAULT;
+				if (j >= MAX_FIELDS) {
+					fprintf(stderr, "WARN: MAX_FIELDS (%d) reached, truncating input data.\n", MAX_FIELDS);
+					break;
+				}
 				j++;
 			}
 		}
@@ -269,8 +273,10 @@ int main(int argc, char **argv)
 				for (tok = strtok(tmp, ",");
 				     tok;
 				     tok = strtok(NULL, ",")) {
-					if (fp.num >= MAX_FIELDS)
+					if (fp.num >= MAX_FIELDS) {
+						fprintf(stderr, "WARN: MAX_FIELDS (%d) reached, truncating given keys.\n", MAX_FIELDS);
 						break;
+					}
 					fp.params[fp.num++].name = tok;
 				}
 				break;

-- 
Regards,
Andreas Henriksson

      reply	other threads:[~2008-06-30 18:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-29  9:56 [Fwd: Bug#488430: iproute: lnstat causes segmentation fault] Andreas Henriksson
2008-06-30 17:36 ` Stephen Hemminger
2008-06-30 18:20   ` Andreas Henriksson [this message]

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=1214850041.16171.53.camel@amd64.fatal.se \
    --to=andreas@fatal.se \
    --cc=488430@bugs.debian.org \
    --cc=andrew@avito.co.uk \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.com \
    /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).