From: Stephen Hemminger <stephen@networkplumber.org>
To: "Michał Łyszczek" <michal.lyszczek@bofc.pl>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH v2 iproute2] libnetlink.c, ss.c: properly handle fread() errors
Date: Fri, 1 Nov 2019 09:38:03 -0700 [thread overview]
Message-ID: <20191101093803.4c10c04a@hermes.lan> (raw)
In-Reply-To: <20191029111311.7000-1-michal.lyszczek@bofc.pl>
On Tue, 29 Oct 2019 12:13:11 +0100
Michał Łyszczek <michal.lyszczek@bofc.pl> wrote:
> fread(3) returns size_t data type which is unsigned, thus check
> `if (fread(...) < 0)' is always false. To check if fread(3) has
> failed, user should check error indicator with ferror(3).
>
> This commit also changes read logic a little bit by being less
> forgiving for errors. Previous logic was checking if fread(3)
> read *at least* required ammount of data, now code checks if
> fread(3) read *exactly* expected ammount of data. This makes
> sense because code parses very specific binary file, and reading
> even 1 less/more byte than expected, will later corrupt data anyway.
>
> Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
>
> ---
> v1 -> v2: fread(3) can also return error on truncated reads and
> not only on 0bytes read (suggested by Stephen Hemminger)
>
Thanks, applied.
Isn't error handling messy.
next prev parent reply other threads:[~2019-11-01 16:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-24 21:20 [PATCH iproute2] libnetlink.c, ss.c: properly handle fread() error Michał Łyszczek
2019-10-29 4:21 ` Stephen Hemminger
2019-10-29 11:13 ` [PATCH v2 iproute2] libnetlink.c, ss.c: properly handle fread() errors Michał Łyszczek
2019-11-01 16:38 ` Stephen Hemminger [this message]
2019-10-29 11:35 ` [PATCH iproute2] libnetlink.c, ss.c: properly handle fread() error michal.lyszczek
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=20191101093803.4c10c04a@hermes.lan \
--to=stephen@networkplumber.org \
--cc=michal.lyszczek@bofc.pl \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.