Covscan: Fixes for obvious programming mistakes
Subsystems (2)
v2 cover Covscan: Fixes for obvious programming mistakes
This series collects those patches from v1 which are clear programming flaws.
No changes to the actual patches, just splitting into smaller series.
Phil Sutter (3):
iproute_lwtunnel: csum_mode value checking was ineffective
iproute_lwtunnel: Argument to strerror must be positive tipc/node: Fix socket fd check in cmd_node_get_addr()
ip/iproute_lwtunnel.c | 9 +++++---- tipc/node.c | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.13.1
PATCH v2 1/3 iproute_lwtunnel: csum_mode value checking was ineffective
ila_csum_name2mode() returning -1 on error but being declared as returning __u8 doesn't make much sense. Change the code to correctly detect this issue. Checking for __u8 overruns shouldn't be necessary though since ila_csum_name2mode() return values are well-defined.
--- ip/iproute_lwtunnel.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
ip/iproute_lwtunnel.c +4 -3
@@ -171,7 +171,7 @@ static char *ila_csum_mode2name(__u8 csum_mode) } } -static __u8 ila_csum_name2mode (char *name) +static int ila_csum_name2mode (char *name) {if (strcmp (name,"adj-transport" ) ==0 )return ILA_CSUM_ADJUST_TRANSPORT ;
@@ -517,7 +517,7 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,while (argc >0 ) {if (strcmp (*argv,"csum-mode" ) ==0 ) { -__u8 csum_mode; +int csum_mode;NEXT_ARG ();
@@ -526,7 +526,8 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,invarg ("\"csum-mode\" value is invalid\n" , *argv); -rta_addattr8 (rta,1024 ,ILA_ATTR_CSUM_MODE , csum_mode); +rta_addattr8 (rta,1024 ,ILA_ATTR_CSUM_MODE , + (__u8 )csum_mode); argc--; argv++; }else {
Signature · 1 line
2.13.1
PATCH v2 2/3 iproute_lwtunnel: Argument to strerror must be positive
In reply to Phil Sutter--- ip/iproute_lwtunnel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/iproute_lwtunnel.c +1 -1
@@ -643,7 +643,7 @@ static int lwt_parse_bpf(struct rtattr *rta, size_t len, err =bpf_parse_common (bpf_type, &cfg, &bpf_cb_ops, &x);if (err <0 ) {fprintf (stderr,"Failed to parse eBPF program: %s\n" , -strerror (err)); +strerror (-err));return -1 ; }rta_nest_end (rta, nest);
Signature · 1 line
2.13.1
RE: [iproute PATCH v2 2/3] iproute_lwtunnel: Argument to strerror must be positive
From: Phil Sutter
Quoted 11 lines
Sent: 17 August 2017 18:10
Signed-off-by Phil Sutter <[email protected]>--- ip/iproute_lwtunnel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)ip/iproute_lwtunnel.c +0
-0
ip/iproute_lwtunnel.c static int lwt_parse_bpf(struct rtattr *rta, size_t len, · line 646
Quoted 5 lines
ip/iproute_lwtunnel.c +1
-1@@ -643,7 +643,7 @@ static int lwt_parse_bpf(struct rtattr *rta, size_t len, err =bpf_parse_common (bpf_type, &cfg, &bpf_cb_ops, &x);if (err <0 ) {fprintf (stderr,"Failed to parse eBPF program: %s\n" , -strerror (err)); +strerror (-err));
If we are in userspace I'd expect errno values to be +ve. Returning a -ve errno is very non-standard.
David
Re: [iproute PATCH v2 2/3] iproute_lwtunnel: Argument to strerror must be positive
Quoted 7 lines · David Laight
From: Phil Sutter
Quoted 6 lines
Sent: 17 August 2017 18:10
Signed-off-by Phil Sutter <[email protected]>--- ip/iproute_lwtunnel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
ip/iproute_lwtunnel.c static int lwt_parse_bpf(struct rtattr *rta, size_t len, · line 646
Quoted 10 lines
ip/iproute_lwtunnel.c +1
-1@@ -643,7 +643,7 @@ static int lwt_parse_bpf(struct rtattr *rta, size_t len, err =bpf_parse_common (bpf_type, &cfg, &bpf_cb_ops, &x);if (err <0 ) {fprintf (stderr,"Failed to parse eBPF program: %s\n" , -strerror (err)); +strerror (-err));If we are in userspace I'd expect errno values to be +ve. Returning a -ve errno is very non-standard.
This is because bpf_parse() returns the number of instructions parsed or a negative return code. We could change it to return instructions * -1 or a positive return code, but that's even more insane than calling strerror(-err), isn't it?
Cheers, Phil
PATCH v2 3/3 tipc/node: Fix socket fd check in cmd_node_get_addr()
In reply to Phil Suttersocket() returns -1 on error, not 0.
--- tipc/node.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tipc/node.c +2 -1
@@ -109,7 +109,8 @@ static int cmd_node_get_addr(struct nlmsghdr *nlh, const struct cmd *cmd,socklen_t sz =sizeof (struct sockaddr_tipc );struct sockaddr_tipc addr; -if (!(sk =socket (AF_TIPC ,SOCK_RDM ,0 ))) { + sk =socket (AF_TIPC ,SOCK_RDM ,0 ); +if (sk <0 ) {fprintf (stderr,"opening TIPC socket: %s\n" ,strerror (errno));return -1 ; }
Signature · 1 line
2.13.1
Quoted 5 lines · On Thu, 17 Aug 2017 19:09:29 +0200 Phil Sutter <[email protected]> wrote:
This series collects those patches from v1 which are clear programming flaws.
No changes to the actual patches, just splitting into smaller series.
Quoted 9 lines
Phil Sutter (3):
iproute_lwtunnel:csum_modevalue checking was ineffective
iproute_lwtunnel: Argument to strerror must be positive tipc/node: Fix socket fd check incmd_node_get_addr()ip/iproute_lwtunnel.c | 9 +++++---- tipc/node.c | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-)
Accepted.