Pārlūkot izejas kodu

lib/srdb1: memset db connection structure earlier in db_bind_mod()

Daniel-Constantin Mierla 6 gadi atpakaļ
vecāks
revīzija
1b014d65e2
1 mainītis faili ar 6 papildinājumiem un 5 dzēšanām
  1. 6 5
      src/lib/srdb1/db.c

+ 6 - 5
src/lib/srdb1/db.c

@@ -163,6 +163,12 @@ int db_bind_mod(const str* mod, db_func_t* mydbf)
 		LM_CRIT("null dbf parameter\n");
 		return -1;
 	}
+
+	/* for safety we initialize mydbf with 0 (this will cause
+	 *  a segfault immediately if someone tries to call a function
+	 *  from it without checking the return code from bind_dbmod */
+	memset((void*)mydbf, 0, sizeof(db_func_t));
+
 	if (mod->len > MAX_URL_LENGTH)
 	{
 		LM_ERR("SQL URL too long\n");
@@ -178,11 +184,6 @@ int db_bind_mod(const str* mod, db_func_t* mydbf)
 	memcpy(name+3, mod->s, mod->len);
 	name[mod->len+3] = 0;
 
-	/* for safety we initialize mydbf with 0 (this will cause
-	 *  a segfault immediately if someone tries to call a function
-	 *  from it without checking the return code from bind_dbmod */
-	memset((void*)mydbf, 0, sizeof(db_func_t));
-
 	p = strchr(name, ':');
 	if (p) {
 		len = p - name;