[sr-dev] git:pd/msrp: lib/srdb1: while converting strings to int/ bigint check for invalid characters

Peter Dunkley peter.dunkley at crocodile-rcs.com
Wed Feb 6 14:51:40 CET 2013


Module: sip-router
Branch: pd/msrp
Commit: af7d4496febf95e56b604849a8f818e688b21f53
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=af7d4496febf95e56b604849a8f818e688b21f53

Author: Ovidiu Sas <osas at voipembedded.com>
Committer: Ovidiu Sas <osas at voipembedded.com>
Date:   Mon Feb  4 10:59:10 2013 -0500

lib/srdb1: while converting strings to int/bigint check for invalid characters

---

 lib/srdb1/db_ut.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/srdb1/db_ut.c b/lib/srdb1/db_ut.c
index c57ef4d..0fa4cf5 100644
--- a/lib/srdb1/db_ut.c
+++ b/lib/srdb1/db_ut.c
@@ -73,18 +73,23 @@
 inline int db_str2int(const char* _s, int* _v)
 {
 	long tmp;
+	char* p = NULL;
 
 	if (!_s || !_v) {
 	       LM_ERR("Invalid parameter value\n");
 	       return -1;
 	}
 
-	tmp = strtoul(_s, 0, 10);
+	tmp = strtoul(_s, &p, 10);
 	if ((tmp == ULONG_MAX && errno == ERANGE) || 
 	    (tmp < INT_MIN) || (tmp > UINT_MAX)) {
 		LM_ERR("Value out of range\n");
 		return -1;
 	}
+	if (p && *p != '\0') {
+		LM_ERR("Unexpected characters: [%s]\n", p);
+		return -2;
+	}
 
 	*_v = (int)tmp;
 	return 0;
@@ -94,17 +99,22 @@ inline int db_str2int(const char* _s, int* _v)
 inline int db_str2longlong(const char* _s, long long * _v)
 {
 	long long tmp;
+	char* p = NULL;
 
 	if (!_s || !_v) {
 	       LM_ERR("Invalid parameter value\n");
 	       return -1;
 	}
 
-	tmp = strtoll(_s, 0, 10);
+	tmp = strtoll(_s, &p, 10);
 	if (errno == ERANGE) {
 		LM_ERR("Value out of range\n");
 		return -1;
 	}
+	if (p && *p != '\0') {
+		LM_ERR("Unexpected characters: [%s]\n", p);
+		return -2;
+	}
 
 	*_v = tmp;
 	return 0;




More information about the sr-dev mailing list