Browse Source

htable: safety check for null db values

- with some db engines the non-null condition might not be enforced,
  resulting in working with null values
- reported by Eric Hiller
Daniel-Constantin Mierla 14 years ago
parent
commit
5cd534834b
1 changed files with 8 additions and 0 deletions
  1. 8 0
      modules_k/htable/ht_db.c

+ 8 - 0
modules_k/htable/ht_db.c

@@ -199,6 +199,10 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
 			cnt++;
 			/* not NULL values enforced in table definition ?!?! */
 			kname.s = (char*)(RES_ROWS(db_res)[i].values[0].val.string_val);
+			if(kname.s==NULL) {
+				LM_ERR("null key in row %d\n", i);
+				goto error;
+			}
 			kname.len = strlen(kname.s);
 			ktype = RES_ROWS(db_res)[i].values[1].val.int_val;
 			if(ktype==0 && last_ktype==1)
@@ -257,6 +261,10 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
 			last_ktype = ktype;
 			vtype = RES_ROWS(db_res)[i].values[2].val.int_val;
 			kvalue.s = (char*)(RES_ROWS(db_res)[i].values[3].val.string_val);
+			if(kvalue.s==NULL) {
+				LM_ERR("null value in row %d\n", i);
+				goto error;
+			}
 			kvalue.len = strlen(kvalue.s);
 
 			/* add to hash */