[sr-dev] git:master:baf2d095: core/socket_info: use internal str2int() instead of strtol()

Mikko Lehto mslehto at iki.fi
Sun Jun 25 19:14:40 CEST 2017


Module: kamailio
Branch: master
Commit: baf2d095b1d4dcc932ece9d48a6a8c397fa7b1a7
URL: https://github.com/kamailio/kamailio/commit/baf2d095b1d4dcc932ece9d48a6a8c397fa7b1a7

Author: Mikko Lehto <mslehto at iki.fi>
Committer: Mikko Lehto <mslehto at iki.fi>
Date: 2017-06-24T13:27:40+03:00

core/socket_info: use internal str2int() instead of strtol()

- strtol() works only for null terminated strings
- fix for issue GH #1161

---

Modified: src/core/socket_info.c

---

Diff:  https://github.com/kamailio/kamailio/commit/baf2d095b1d4dcc932ece9d48a6a8c397fa7b1a7.diff
Patch: https://github.com/kamailio/kamailio/commit/baf2d095b1d4dcc932ece9d48a6a8c397fa7b1a7.patch

---

diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index f280f2dcb0..62a15f4c93 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -1973,7 +1973,7 @@ int parse_protohostport(str* ins, sr_phostp_t *r)
 	char* second; /* second ':' occurrence */
 	char* p;
 	int bracket;
-	char* tmp;
+	str tmp=STR_NULL;
 
 	first=second=0;
 	bracket=0;
@@ -2012,15 +2012,20 @@ int parse_protohostport(str* ins, sr_phostp_t *r)
 	if (second) { /* 2 ':' found => check if valid */
 		if (parse_proto((unsigned char*)ins->s, first-ins->s, &r->proto)<0)
 			goto error_proto;
-		r->port=strtol(second+1, &tmp, 10);
-		if ((tmp==0)||(*tmp)||(tmp==second+1)) goto error_port;
+
+		tmp.s=second+1;
+		tmp.len=(ins->s + ins->len) - tmp.s;
+
+		if (str2int(&tmp, (unsigned int *)&(r->port))<0) goto error_port;
+
 		r->host.s=first+1;
 		r->host.len=(int)(second-r->host.s);
 		goto end;
 	}
 	/* only 1 ':' found => it's either proto:host or host:port */
-	r->port=strtol(first+1, &tmp, 10);
-	if ((tmp==0)||(*tmp)||(tmp==first+1)){
+	tmp.s=first+1;
+	tmp.len=(ins->s + ins->len) - tmp.s;
+	if (str2int(&tmp, (unsigned int *)&(r->port))<0) {
 		/* invalid port => it's proto:host */
 		if (parse_proto((unsigned char*)ins->s, first-ins->s, &r->proto)<0)
 			goto error_proto;




More information about the sr-dev mailing list