[spp] [PATCH 19/57] spp_vf: refactor parsing server ip address

x-fn-spp at sl.ntt-tx.co.jp x-fn-spp at sl.ntt-tx.co.jp
Thu Dec 28 05:55:26 CET 2017


From: Hiroyuki Nakamura <nakamura.hioryuki at po.ntt-tx.co.jp>

The following two changes are made in parse_app_server()
in order to get server IP address.
* Check the number of characters in IP address string.
* Add terminator '\0' to IP address string.

Signed-off-by: Kentaro Watanabe <watanabe.kentaro.z01 at as.ntt-tx.co.jp>
Signed-off-by: Yasufum Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
---
 src/vf/spp_vf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c
index 7bb1ac0..e5dc1c9 100644
--- a/src/vf/spp_vf.c
+++ b/src/vf/spp_vf.c
@@ -329,16 +329,20 @@ static int
 parse_app_server(const char *server_str, char *server_ip, int *server_port)
 {
 	const char delim[2] = ":";
-	int pos = 0;
+	unsigned int pos = 0;
 	int port = 0;
 	char *endptr = NULL;
 
 	pos = strcspn(server_str, delim);
+	if (pos >= strlen(server_str))
+		return -1;
+
 	port = strtol(&server_str[pos+1], &endptr, 0);
 	if (unlikely(&server_str[pos+1] == endptr) || unlikely(*endptr != '\0'))
 		return -1;
 
 	memcpy(server_ip, server_str, pos);
+	server_ip[pos] = '\0';
 	*server_port = port;
 	RTE_LOG(DEBUG, APP, "Set server ip   = %s\n", server_ip);
 	RTE_LOG(DEBUG, APP, "Set server port = %d\n", *server_port);
-- 
1.9.1



More information about the spp mailing list