Skip to contentSkip to conversation

ipvsadm: init svc in ipvs_get_service

PATCH Applied Julian Anastasov 3 participants 3 messages Aug 24, 2013 – Aug 27, 2013 IPVS

lore
Share & tools
lore

Julian Anastasov

author maintainer
#0 lore raw

PATCH 1/1 ipvsadm: init svc in ipvs_get_service

ipvs_get_service() needs to init the allocated svc for the non-netlink case due to the used CHECK_COMPAT_SVC macro that includes pe_name[0] check in CHECK_PE. Use calloc to avoid reading random data.

For the netlink case use malloc as before.

---
 libipvs/libipvs.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)
libipvs/libipvs.c +16 -9
index 04473fb..d2fec49 100644
@@ -930,22 +930,18 @@ ipvs_get_service(__u32 fwmark, __u16 af, __u16 protocol, union nf_inet_addr addr
 	ipvs_service_entry_t *svc;
 	socklen_t len;
 
-	len = sizeof(*svc);
-	if (!(svc = malloc(len)))
-		return NULL;
-
 	ipvs_func = ipvs_get_service;
 
-	svc->fwmark = fwmark;
-	svc->af = af;
-	svc->protocol = protocol;
-	svc->addr = addr;
-	svc->port = port;
 #ifdef LIBIPVS_USE_NL
 	if (try_nl) {
 		struct ip_vs_get_services *get;
 		struct nl_msg *msg;
 		ipvs_service_t tsvc;
+
+		svc = malloc(sizeof(*svc));
+		if (!svc)
+			return NULL;
+
 		tsvc.fwmark = fwmark;
 		tsvc.af = af;
 		tsvc.protocol= protocol;
@@ -978,6 +974,17 @@ ipvs_get_service_err2:
 	}
 #endif
 
+	len = sizeof(*svc);
+	svc = calloc(1, len);
+	if (!svc)
+		return NULL;
+
+	svc->fwmark = fwmark;
+	svc->af = af;
+	svc->protocol = protocol;
+	svc->addr = addr;
+	svc->port = port;
+
 	CHECK_COMPAT_SVC(svc, NULL);
 	if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_SERVICE,
 		       (char *)svc, &len)) {
Signature · 1 line
1.7.3.4
maintainer Applied
#1 lore raw
Quoted 8 lines · Julian Anastasov

ipvs_get_service() needs to init the allocated svc for the non-netlink case due to the used CHECK_COMPAT_SVC macro that includes pe_name[0] check in CHECK_PE. Use calloc to avoid reading random data.

For the netlink case use malloc as before.

Thanks, applied.

#2 lore raw
In reply to Julian Anastasov

Thanks for fixing this.

Ryan

Quoted 69 lines · Julian Anastasov

ipvs_get_service() needs to init the allocated svc for the non-netlink case due to the used CHECK_COMPAT_SVC macro that includes pe_name[0] check in CHECK_PE. Use calloc to avoid reading random data.

For the netlink case use malloc as before.

---
 libipvs/libipvs.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)
libipvs/libipvs.c +16 -9
index 04473fb..d2fec49 100644
@@ -930,22 +930,18 @@ ipvs_get_service(__u32 fwmark, __u16 af, __u16 protocol, union nf_inet_addr addr
 	ipvs_service_entry_t *svc;
 	socklen_t len;
 
-	len = sizeof(*svc);
-	if (!(svc = malloc(len)))
-		return NULL;
-
 	ipvs_func = ipvs_get_service;
 
-	svc->fwmark = fwmark;
-	svc->af = af;
-	svc->protocol = protocol;
-	svc->addr = addr;
-	svc->port = port;
 #ifdef LIBIPVS_USE_NL
 	if (try_nl) {
 		struct ip_vs_get_services *get;
 		struct nl_msg *msg;
 		ipvs_service_t tsvc;
+
+		svc = malloc(sizeof(*svc));
+		if (!svc)
+			return NULL;
+
 		tsvc.fwmark = fwmark;
 		tsvc.af = af;
 		tsvc.protocol= protocol;
@@ -978,6 +974,17 @@ ipvs_get_service_err2:
 	}
 #endif
 
+	len = sizeof(*svc);
+	svc = calloc(1, len);
+	if (!svc)
+		return NULL;
+
+	svc->fwmark = fwmark;
+	svc->af = af;
+	svc->protocol = protocol;
+	svc->addr = addr;
+	svc->port = port;
+
 	CHECK_COMPAT_SVC(svc, NULL);
 	if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_SERVICE,
 		       (char *)svc, &len)) {
Signature · 6 lines
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe lvs-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html