From: Phil Sutter <phil@nwl.cc> Date: 2017-08-21 17:09:09
This series collects patches from v1 addressing miscellaneous issues
detected by covscan.
No changes to the actual patches, just splitting into smaller series.
Phil Sutter (7):
nstat: Avoid passing negative fd to fdopen()
ss: Make sure index variable is >= 0
ss: Make sure scanned index value to unix_state_map is sane
netem/maketable: Check return value of fscanf()
lib/bpf: Check return value of write()
lib/fs: Fix and simplify make_path()
lib/libnetlink: Don't pass NULL parameter to memcpy()
lib/bpf.c | 3 ++-
lib/fs.c | 20 +++++---------------
lib/libnetlink.c | 6 ++++--
misc/nstat.c | 15 +++++++++++----
misc/ss.c | 5 +++--
netem/maketable.c | 4 ++--
6 files changed, 27 insertions(+), 26 deletions(-)
--
2.13.1
From: Phil Sutter <phil@nwl.cc> Date: 2017-08-21 17:08:31
This is merely to silence the compiler warning. If write to stderr
failed, assume that printing an error message will fail as well so don't
even try.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
lib/bpf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
From: Phil Sutter <phil@nwl.cc> Date: 2017-08-21 17:08:38
Introduce a wrapper which does the sanity checking and returns NULL
in case fd is invalid.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
misc/nstat.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
From: Phil Sutter <phil@nwl.cc> Date: 2017-08-21 17:08:44
Both addattr_l() and rta_addattr_l() may be called with NULL data
pointer and 0 alen parameters. Avoid calling memcpy() in that case.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
lib/libnetlink.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
@@ -871,7 +871,8 @@ int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,rta=NLMSG_TAIL(n);rta->rta_type=type;rta->rta_len=len;-memcpy(RTA_DATA(rta),data,alen);+if(alen)+memcpy(RTA_DATA(rta),data,alen);n->nlmsg_len=NLMSG_ALIGN(n->nlmsg_len)+RTA_ALIGN(len);return0;}
@@ -958,7 +959,8 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type,subrta=(structrtattr*)(((char*)rta)+RTA_ALIGN(rta->rta_len));subrta->rta_type=type;subrta->rta_len=len;-memcpy(RTA_DATA(subrta),data,alen);+if(alen)+memcpy(RTA_DATA(subrta),data,alen);rta->rta_len=NLMSG_ALIGN(rta->rta_len)+RTA_ALIGN(len);return0;}
From: Phil Sutter <phil@nwl.cc> Date: 2017-08-21 17:08:57
This shouldn't happen but relying upon external data without checking
may lead to unexpected results.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
misc/ss.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Phil Sutter <phil@nwl.cc> Date: 2017-08-21 17:09:03
Calling stat() before mkdir() is racey: The entry might change in
between. Also, the call to stat() seems to exist only to check if the
directory exists already. So simply call mkdir() unconditionally and
catch only errors other than EEXIST.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
lib/fs.c | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
From: Stephen Hemminger <stephen@networkplumber.org> Date: 2017-08-22 00:23:30
On Mon, 21 Aug 2017 19:08:07 +0200
Phil Sutter [off-list ref] wrote:
quoted hunk
Introduce a wrapper which does the sanity checking and returns NULL
in case fd is invalid.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
misc/nstat.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
From: Stephen Hemminger <stephen@networkplumber.org> Date: 2017-08-22 00:34:06
On Mon, 21 Aug 2017 19:08:08 +0200
Phil Sutter [off-list ref] wrote:
quoted hunk
This shouldn't happen but relying upon external data without checking
may lead to unexpected results.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
misc/ss.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Phil Sutter <phil@nwl.cc> Date: 2017-08-22 10:48:09
On Mon, Aug 21, 2017 at 05:23:23PM -0700, Stephen Hemminger wrote:
On Mon, 21 Aug 2017 19:08:07 +0200
Phil Sutter [off-list ref] wrote:
quoted
Introduce a wrapper which does the sanity checking and returns NULL
in case fd is invalid.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
misc/nstat.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)