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

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;
                    /* 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)) {
                                   g = find_realtime_gw(name, at, sin);
                                   g = g->next;
                    } else {

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


Does this issue report exist on the issue tracker?

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.


This is now on the issue tracker as ID 0019229.

Thanks :smile: