netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hangbin Liu <haliu@redhat.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: "'Hangbin Liu'" <liuhangbin@gmail.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Phil Sutter <phil@nwl.cc>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: Re: [PATCH iproute2] ip route: check ftell, fseek return value
Date: Wed, 7 Sep 2016 21:50:40 +0800	[thread overview]
Message-ID: <20160907135040.GA2861@leo.usersys.redhat.com> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6DB00F5252@AcuExch.aculab.com>

On Tue, Sep 06, 2016 at 11:18:00AM +0000, David Laight wrote:
> From: Hangbin Liu
> > Sent: 06 September 2016 07:40
> > ftell() may return -1 in error case, which is not handled and therefore pass a
> > negative offset to fseek(). The return code of fseek() is also not checked.
> > 
> > Reported-by: Phil Sutter <phil@nwl.cc>
> > Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> > ---
> >  ip/iproute.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> > 
> > diff --git a/ip/iproute.c b/ip/iproute.c
> > index 3da23af..ba877dc 100644
> > --- a/ip/iproute.c
> > +++ b/ip/iproute.c
> > @@ -1859,7 +1859,11 @@ static int iproute_restore(void)
> >  	if (route_dump_check_magic())
> >  		exit(-1);
> > 
> > -	pos = ftell(stdin);
> > +	if ((pos = ftell(stdin)) == -1) {
> 
> Don't put assignments in conditionals.
> 
> > +		perror("Failed to restore: ftell");
> > +		exit(errno);
> 
> errno is not a valid argument to exit().

Hi David,

Thanks for the advice. I will send PATCHv2 to fix them.

> 
> ...
> 
> Actually WTF is this code trying to do.
> stdin is vere likely to be a pipe, so expecting to seek on it
> seems very likely to fail.

I will fix the return code handle issue first and try investigate the pipe
issue later.

Regards
Hangbin

      reply	other threads:[~2016-09-07 13:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-06  6:39 [PATCH iproute2] ip route: check ftell, fseek return value Hangbin Liu
2016-09-06 10:05 ` Phil Sutter
2016-09-06 11:18 ` David Laight
2016-09-07 13:50   ` Hangbin Liu [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=20160907135040.GA2861@leo.usersys.redhat.com \
    --to=haliu@redhat.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=liuhangbin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=phil@nwl.cc \
    --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).