netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Andreas Henriksson <andreas@fatal.se>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2] arpd: drop unnecessary explicit null termination
Date: Sun, 3 Jan 2016 09:04:04 -0800	[thread overview]
Message-ID: <20160103090404.054e724b@xeon-e3> (raw)
In-Reply-To: <1451837384-2177-1-git-send-email-andreas@fatal.se>

On Sun,  3 Jan 2016 17:09:44 +0100
Andreas Henriksson <andreas@fatal.se> wrote:

> This is a followup to a previous commit 61170fd88d264c
> "get rid of unnecessary fgets() buffer size limitation".
> 
> If fgets guarantees buffer will be null terminated in the
> given size, then we can also drop the explicit termination.
> 
> While at it, also add an unrelated FIXME comment about
> potential unlikely long comment handling bug spotted in
> nearby code.
> 
> Signed-off-by: Andreas Henriksson <andreas@fatal.se>
> ---
>  misc/arpd.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/misc/arpd.c b/misc/arpd.c
> index 6bb9bd1..3be700d 100644
> --- a/misc/arpd.c
> +++ b/misc/arpd.c
> @@ -702,12 +702,16 @@ int main(int argc, char **argv)
>  			goto do_abort;
>  		}
>  
> -		buf[sizeof(buf)-1] = 0;
>  		while (fgets(buf, sizeof(buf), fp)) {
>  			__u8 b1[6];
>  			char ipbuf[128];
>  			char macbuf[128];
>  
> +			/* FIXME: this does not properly handle the case where
> +			 * the comment line is longer than sizeof(buf).
> +			 * Should check if buf contains '\n' or skip upcoming
> +			 * bufs until '\n' is found.
> +			 */
>  			if (buf[0] == '#')
>  				continue;
>  

Rather than adding a big FIXME, please fix the problem.

Easiest fix would be just increase sizeof(buf) to BUFSIZ (4k) which
should fix any rational use of the file.

Other alternatives would be to use fscanf or getline.

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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-03 16:09 [PATCH iproute2] arpd: drop unnecessary explicit null termination Andreas Henriksson
2016-01-03 17:04 ` Stephen Hemminger [this message]
2016-01-03 18:39   ` [PATCH iproute2 v2 1/2] " Andreas Henriksson
2016-01-03 18:39     ` [PATCH iproute2 v2 2/2] arpd: fix parsing of unlikely long comments Andreas Henriksson
2016-01-03 18:44       ` Andreas Henriksson
2016-01-03 23:04         ` Stephen Hemminger

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=20160103090404.054e724b@xeon-e3 \
    --to=stephen@networkplumber.org \
    --cc=andreas@fatal.se \
    --cc=netdev@vger.kernel.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).