--- channels/chan_sip.c 2004-11-25 23:08:29.471065664 -0500 +++ channels/chan_sip.c 2004-11-25 23:07:15.072375984 -0500 @@ -6540,8 +6540,12 @@ if (e) *e = '\0'; ast_log(LOG_DEBUG, "Found promiscuous redirection to 'SIP/%s'\n", s); - if (p->owner) - snprintf(p->owner->call_forward, sizeof(p->owner->call_forward), "SIP/%s", s); + if (p->owner) { + if (!strcmp(p->owner->exten,s)) + ast_log(LOG_DEBUG, "Aborted - Possible loop condition averted\n"); + else + snprintf(p->owner->call_forward, sizeof(p->owner->call_forward), "SIP/%s", s); + } } else { e = strchr(tmp, '@'); if (e) @@ -6552,8 +6556,12 @@ if (!strncasecmp(s, "sip:", 4)) s += 4; ast_log(LOG_DEBUG, "Found 302 Redirect to extension '%s'\n", s); - if (p->owner) - strncpy(p->owner->call_forward, s, sizeof(p->owner->call_forward) - 1); + if (p->owner) { + if (!strcmp(p->owner->exten,s)) + ast_log(LOG_DEBUG, "Aborted - Possible loop condition averted\n"); + else + strncpy(p->owner->call_forward, s, sizeof(p->owner->call_forward) - 1); + } } }