Explorar o código

The calculate_routeset_length() produces an invalid result in the case
dlg_t.hooks.last_route is set (and .first_route not).
Applied patch fixes that (and should hopefully be a bit cleaner).

Closes #SER-421.

Bogdan Pintea %!s(int64=16) %!d(string=hai) anos
pai
achega
713d776ef5
Modificáronse 1 ficheiros con 14 adicións e 15 borrados
  1. 14 15
      modules/tm/dlg.c

+ 14 - 15
modules/tm/dlg.c

@@ -1092,31 +1092,30 @@ int dlg_request_uas(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_re
 int calculate_routeset_length(dlg_t* _d)
 {
 	int len;
-	rr_t* ptr;
+	rr_t *ptr;
 
-	len = 0;
-	ptr = _d->hooks.first_route;
+	if (! _d->route_set)
+		return 0;
 
-	if (ptr) {
-		len = ROUTE_PREFIX_LEN;
-		len += CRLF_LEN;
-	}
+	len = ROUTE_PREFIX_LEN;
 
-	while(ptr) {
+	for (ptr = _d->hooks.first_route; ptr; ptr = ptr->next) {
 		len += ptr->len;
-		ptr = ptr->next;
-		if (ptr) len += ROUTE_SEPARATOR_LEN;
-	} 
-
+		len += ROUTE_SEPARATOR_LEN;
+	}
 	if (_d->hooks.last_route) {
-		len += ROUTE_SEPARATOR_LEN + 2; /* < > */
-		len += _d->hooks.last_route->len;
+		if (_d->hooks.first_route)
+			len += ROUTE_SEPARATOR_LEN;
+		len += _d->hooks.last_route->len + 2; /* < > */
+	} else {
+		len -= ROUTE_SEPARATOR_LEN;
 	}
 
+	len += CRLF_LEN;
+
 	return len;
 }
 
-
 /*
  *
  * Print the route set