Browse code

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)
(cherry picked from commit 20276e667631ec281851c2ef58d71863ae2318c4)

Daniel-Constantin Mierla authored on 04/03/2014 08:59:07
Showing 1 changed files
... ...
@@ -228,13 +228,16 @@ void sql_reset_result(sql_result_t *res)
228 228
 	{
229 229
 		for(i=0; i<res->nrows; i++)
230 230
 		{
231
-			for(j=0; j<res->ncols; j++)
231
+			if(res->vals[i])
232 232
 			{
233
-				if(res->vals[i][j].flags&PV_VAL_STR
234
-						&& res->vals[i][j].value.s.len>0)
235
-					pkg_free(res->vals[i][j].value.s.s);
233
+				for(j=0; j<res->ncols; j++)
234
+				{
235
+					if(res->vals[i][j].flags&PV_VAL_STR
236
+							&& res->vals[i][j].value.s.len>0)
237
+						pkg_free(res->vals[i][j].value.s.s);
238
+				}
239
+				pkg_free(res->vals[i]);
236 240
 			}
237
-			pkg_free(res->vals[i]);
238 241
 		}
239 242
 		pkg_free(res->vals);
240 243
 		res->vals = NULL;