libipvs: Initialize ipvs_service_t variable
PATCH 1/1 libipvs: Initialize ipvs_service_t variable
The ipvs_get_service function declares an ipvs_service_t type variable and initializes some of the values, but should really start by initializing the entire structure.
--- libipvs/libipvs.c | 1 + 1 file changed, 1 insertion(+)
libipvs/libipvs.c +1 -0
@@ -942,6 +942,7 @@ ipvs_get_service(__u32 fwmark, __u16 af, __u16 protocol, union nf_inet_addr addrif (!svc)return NULL ; +memset (&tsvc,0 ,sizeof (tsvc)); tsvc.fwmark = fwmark; tsvc.af = af; tsvc.protocol= protocol;
Signature · 1 line
1.8.1.4
Julian Anastasov
maintainerHello,
Quoted 23 lines · Ryan O'Hara
The
ipvs_get_servicefunction declares anipvs_service_ttype variable and initializes some of the values, but should really start by initializing the entire structure.Signed-off-by Ryan O'Hara <[email protected]>--- libipvs/libipvs.c | 1 + 1 file changed, 1 insertion(+)libipvs/libipvs.c +1
-0@@ -942,6 +942,7 @@ ipvs_get_service(__u32 fwmark, __u16 af, __u16 protocol, union nf_inet_addr addrif (!svc)return NULL ; +memset (&tsvc,0 ,sizeof (tsvc)); tsvc.fwmark = fwmark; tsvc.af = af; tsvc.protocol= protocol;Signature · 1 line
1.8.1.4
Yes, it is a good idea. Another variant is to
change malloc to calloc. May be ipvs_nl_fill_service_attr() can not crash in all cases when reading svc->pe_name[]. As for the kernel part, ip_vs_genl_parse_service() uses just the initialized fields when full_entry=0 for IPVS_CMD_GET_SERVICE but it is better to avoid problems in the future.
Regards
--
Julian Anastasov <[email protected]>
Quoted 22 lines · Julian Anastasov
Hello,
Quoted 17 lines · Ryan O'Hara
The
ipvs_get_servicefunction declares anipvs_service_ttype variable and initializes some of the values, but should really start by initializing the entire structure.Signed-off-by Ryan O'Hara <[email protected]>--- libipvs/libipvs.c | 1 + 1 file changed, 1 insertion(+)libipvs/libipvs.c +0
-0@@ -942,6 +942,7 @@ ipvs_get_service(__u32 fwmark, __u16 af, __u16 protocol, union nf_inet_addr addrif (!svc)return NULL ;
Quoted 13 lines
Quoted 6 lines
libipvs/libipvs.c +1
-0+memset (&tsvc,0 ,sizeof (tsvc)); tsvc.fwmark = fwmark; tsvc.af = af; tsvc.protocol= protocol;Signature · 1 line
1.8.1.4Yes, it is a good idea. Another variant is to
change malloc to calloc. May beipvs_nl_fill_service_attr()can not crash in all cases when reading svc->pe_name[]. As for the kernel part,ip_vs_genl_parse_service()uses just the initialized fields when full_entry=0 forIPVS_CMD_GET_SERVICEbut it is better to avoid problems in the future.
Right. This 'bug' was found while running the code through a static analyzer, which finds all sorts of nit-picks. Since the variable in question here is on the stack, a simple memset seems sufficient. Sorry for trivial patches, just trying to get rid of the complaints from the analyzer.
Ryan
Quoted 4 lines
Regards
--
Julian Anastasov <[email protected]>
Quoted 37 lines · On Fri, 17 Jan 2014 15:15:17 -0600 "Ryan O'Hara" <[email protected]> wrote:
Quoted 22 lines · Julian Anastasov
Hello,
Quoted 17 lines · Ryan O'Hara
The
ipvs_get_servicefunction declares anipvs_service_ttype variable and initializes some of the values, but should really start by initializing the entire structure.Signed-off-by Ryan O'Hara <[email protected]>--- libipvs/libipvs.c | 1 + 1 file changed, 1 insertion(+)libipvs/libipvs.c +0
-0@@ -942,6 +942,7 @@ ipvs_get_service(__u32 fwmark, __u16 af, __u16 protocol, union nf_inet_addr addrif (!svc)return NULL ;Quoted 13 lines
Quoted 6 lines
libipvs/libipvs.c +1
-0+memset (&tsvc,0 ,sizeof (tsvc)); tsvc.fwmark = fwmark; tsvc.af = af; tsvc.protocol= protocol;Signature · 1 line
1.8.1.4Yes, it is a good idea. Another variant is to
change malloc to calloc. May beipvs_nl_fill_service_attr()can not crash in all cases when reading svc->pe_name[]. As for the kernel part,ip_vs_genl_parse_service()uses just the initialized fields when full_entry=0 forIPVS_CMD_GET_SERVICEbut it is better to avoid problems in the future.
Quoted 5 lines
Right. This 'bug' was found while running the code through a static analyzer, which finds all sorts of nit-picks. Since the variable in question here is on the stack, a simple memset seems sufficient. Sorry for trivial patches, just trying to get rid of the complaints from the analyzer.
Thanks Ryan,
Applied the patch.
More followup patches to address more areas are welcome.
Git tree for ipvsadm avail at:
https://git.kernel.org/cgit/utils/kernel/ipvsadm/ipvsadm.git/
Signature · 5 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Sr. Network Kernel Developer at Red Hat Author of http://www.iptv-analyzer.org LinkedIn: http://www.linkedin.com/in/brouer