pdt: reorder checks to avoid null access
authorDaniel-Constantin Mierla <miconda@gmail.com>
Sat, 22 Jul 2017 06:33:22 +0000 (08:33 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Sat, 22 Jul 2017 06:33:22 +0000 (08:33 +0200)
src/modules/pdt/pdt.c

index 6505d8a..09eacac 100644 (file)
@@ -617,21 +617,25 @@ int pdt_load_db(void)
                {
                        /* check for NULL values ?!?! */
                        sdomain.s = (char*)(RES_ROWS(db_res)[i].values[0].val.string_val);
-                       sdomain.len = strlen(sdomain.s);
-
                        p.s = (char*)(RES_ROWS(db_res)[i].values[1].val.string_val);
-                       p.len = strlen(p.s);
-                       
                        d.s = (char*)(RES_ROWS(db_res)[i].values[2].val.string_val);
+
+                       if(p.s==NULL || d.s==NULL || sdomain.s==NULL)
+                       {
+                               LM_ERR("Error - bad values in db\n");
+                               continue;
+                       }
+
+                       sdomain.len = strlen(sdomain.s);
+                       p.len = strlen(p.s);
                        d.len = strlen(d.s);
 
-                       if(p.s==NULL || d.s==NULL || sdomain.s==NULL ||
-                                       p.len<=0 || d.len<=0 || sdomain.len<=0)
+                       if(p.len<=0 || d.len<=0 || sdomain.len<=0)
                        {
                                LM_ERR("Error - bad values in db\n");
                                continue;
                        }
-               
+
                        if(pdt_check_domain!=0 && _ptree_new!=NULL
                                        && pdt_check_pd(_ptree_new, &sdomain, &p, &d)==1)
                        {