]> git.proxmox.com Git - mirror_iproute2.git/commit
libnetlink.c, ss.c: properly handle fread() errors
authorMichał Łyszczek <michal.lyszczek@bofc.pl>
Tue, 29 Oct 2019 11:13:11 +0000 (12:13 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 1 Nov 2019 16:05:41 +0000 (09:05 -0700)
commiteca51239480dfc154a07c496774bf7e7f4fb3d30
tree5c9661ff4dc422ec17654bfc211008b75cb83e7e
parentcb83101626316aed1cb68931ffc4d27e1b56c503
libnetlink.c, ss.c: properly handle fread() errors

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>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
lib/libnetlink.c
misc/ss.c