Explorar o código

usrloc: check on db delete the return value of memchr

When inserting into the database the AOR is split at the @ sign and
if there is no @ sign in the AOR only the domain part is filled and the
user part is left empty.

But for deleting this is not done and the query failed to be executed
and the AOR is not deleted. This PR add this behaviour of only comparing against the
domain part if the AOR doesn't contain a @ sign.
Rick Barenthin hai 1 ano
pai
achega
49276a1f43
Modificáronse 1 ficheiros con 9 adicións e 5 borrados
  1. 9 5
      src/modules/usrloc/urecord.c

+ 9 - 5
src/modules/usrloc/urecord.c

@@ -491,13 +491,17 @@ int db_delete_urecord(urecord_t *_r)
 	vals[0].val.str_val.len = _r->aor.len;
 
 	if(ul_use_domain) {
-		dom = memchr(_r->aor.s, '@', _r->aor.len);
-		vals[0].val.str_val.len = dom - _r->aor.s;
-
 		vals[1].type = DB1_STR;
 		vals[1].nul = 0;
-		vals[1].val.str_val.s = dom + 1;
-		vals[1].val.str_val.len = _r->aor.s + _r->aor.len - dom - 1;
+		dom = memchr(_r->aor.s, '@', _r->aor.len);
+		if(dom == 0) {
+			vals[0].val.str_val.len = 0;
+			vals[1].val.str_val = _r->aor;
+		} else {
+			vals[0].val.str_val.len = dom - _r->aor.s;
+			vals[1].val.str_val.s = dom + 1;
+			vals[1].val.str_val.len = _r->aor.s + _r->aor.len - dom - 1;
+		}
 	}
 
 	if(ul_dbf.use_table(ul_dbh, _r->domain) < 0) {