Coding error in mgcp_chan.c

Not sure this is the right category as I didn’t see a category for reporting bugs and I haven’t seen a post on this issue in several days of searching this forum. The function find_subchannel_and_lock() has a coding error in two locations that prevent the subchannel from being found on non-dynamic gateways. Here is the C code in question from Asterisk version 1.8.3.2:

[code]
for (g = gateways ? gateways : find_realtime_gw(name, at, sin);
g; g = g->next ? g->next : find_realtime_gw(name, at, sin)) {

    [lines omitted]

                    /* not dynamic, check if the name matches */
                    } else if (name) {
                         if (strcasecmp(g->name, at)) {
                            g = g->next;
                            continue;
                         }
                    /* not dynamic, no name, check if the addr matches */
                    } else if (!name && sin) {
                         if ((g->addr.sin_addr.s_addr != sin->sin_addr.s_addr) ||
                             (g->addr.sin_port != sin->sin_port)) {
                              if(!g->next)
                                   g = find_realtime_gw(name, at, sin);
                              else
                                   g = g->next;
                              continue;
                        }
                    } else {
                        continue;
                    }[/code]

Since the “for” statement includes updating “g” from “g->next”, the extra updates to “g” in the code above cause gateway entries to be skipped and responses from those gateways to continually exceed the maximum retry count.

I hope this helps!

Jeff Waltz

Howdy,

Does this issue report exist on the issue tracker? issues.asterisk.org

I don’t see this problem on the issue tracker. Thanks for pointing me to that page. I’ll move/copy this issue to the tracker.

Thanks!

This is now on the issue tracker as ID 0019229.

Thanks :smile: