[sr-dev] git:5.1:e5d96dec: db_postgres: avoid potential double free if sb url parsing fails

Daniel-Constantin Mierla miconda at gmail.com
Fri Dec 8 16:56:15 CET 2017


Module: kamailio
Branch: 5.1
Commit: e5d96dec3f986a2d98ea5e3c09da1fac3f45c14a
URL: https://github.com/kamailio/kamailio/commit/e5d96dec3f986a2d98ea5e3c09da1fac3f45c14a

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-12-08T16:54:29+01:00

db_postgres: avoid potential double free if sb url parsing fails

(cherry picked from commit 3614b4e66d1b57dc722139fc0e1ccd8d838f13ee)

---

Modified: src/modules/db_postgres/pg_uri.c

---

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

---

diff --git a/src/modules/db_postgres/pg_uri.c b/src/modules/db_postgres/pg_uri.c
index 6170de310e..3e4f9a32bc 100644
--- a/src/modules/db_postgres/pg_uri.c
+++ b/src/modules/db_postgres/pg_uri.c
@@ -255,8 +255,10 @@ static int parse_postgres_uri(struct pg_uri *res, str *uri)
 	return 0;
 
 err:
-	if(prev_token)
-		pkg_free(prev_token);
+	if(prev_token) {
+		if(res==NULL || (res->username!=prev_token && res->host!=prev_token))
+			pkg_free(prev_token);
+	}
 	if(res == NULL)
 		return -1;
 	if(res->username) {




More information about the sr-dev mailing list