[sr-dev] git:4.1: sqlops: safety check for result row field

Daniel-Constantin Mierla miconda at gmail.com
Tue Mar 4 11:53:19 CET 2014


Module: sip-router
Branch: 4.1
Commit: 20276e667631ec281851c2ef58d71863ae2318c4
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=20276e667631ec281851c2ef58d71863ae2318c4

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Tue Mar  4 09:59:07 2014 +0100

sqlops: safety check for result row field

- it might not be set in case of a failure in the middle of result
  conversion from db to internal memory
- freeing the partial result could result in a crash
- reported by Juha Heinanen

(cherry picked from commit f27df26ca01394250cbe12c5ccf694c6afd3707f)

---

 modules/sqlops/sql_api.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/modules/sqlops/sql_api.c b/modules/sqlops/sql_api.c
index 6528078..bfd4e96 100644
--- a/modules/sqlops/sql_api.c
+++ b/modules/sqlops/sql_api.c
@@ -228,13 +228,16 @@ void sql_reset_result(sql_result_t *res)
 	{
 		for(i=0; i<res->nrows; i++)
 		{
-			for(j=0; j<res->ncols; j++)
+			if(res->vals[i])
 			{
-				if(res->vals[i][j].flags&PV_VAL_STR
-						&& res->vals[i][j].value.s.len>0)
-					pkg_free(res->vals[i][j].value.s.s);
+				for(j=0; j<res->ncols; j++)
+				{
+					if(res->vals[i][j].flags&PV_VAL_STR
+							&& res->vals[i][j].value.s.len>0)
+						pkg_free(res->vals[i][j].value.s.s);
+				}
+				pkg_free(res->vals[i]);
 			}
-			pkg_free(res->vals[i]);
 		}
 		pkg_free(res->vals);
 		res->vals = NULL;




More information about the sr-dev mailing list