[Home]

Summary:ASTERISK-18078: [patch] Segfault when publishing device states via XMPP and not connected
Reporter:Michael L. Young (elguero)Labels:
Date Opened:2011-06-30 21:27:30Date Closed:2017-10-11 13:36:13
Priority:CriticalRegression?
Status:Closed/CompleteComponents:Resources/res_jabber
Versions:SVN 1.8.4 1.8.5.0 Frequency of
Occurrence
Related
Issues:
must be completed before resolvingASTERISK-18393 Asterisk 1.8.7.0 Blockers
causesASTERISK-18626 The patch found in r333265 on res_jabber.c breaks authentication to a jabber server.
is duplicated byASTERISK-17648 Asterisk crash when it lost connection to Jabber Server
is related toASTERISK-21855 Asterisk crashes when XMPP message is sent (JabberSend) and no internet connection is available
Environment:Attachments:( 0) gdb290812.txt
( 1) res_jabber-segfault-pubsub-not-connected.patch
( 2) res_jabber-segfault-pubsub-not-connected2.patch
Description:When using XMPP PubSub to distribute device states, if the XMPP server disappears and Asterisk tries to publish device states, we will segfault.
Comments:By: Michael L. Young (elguero) 2011-06-30 21:29:27.368-0500

This patch was done against trunk but it applies fine to 1.8 as well.

By: Michael L. Young (elguero) 2011-07-11 14:19:14.522-0500

The first patch did not completely resolve this issue.  Other parts of the code call this function and a segfault occurs.

This second patch hopefully handles this situation properly no matter what function or part of the code is trying to send messages to a XMPP server while it is down or not reachable.

I tested this and it seems to be working.

By: Jonathan Rose (jrose) 2011-07-18 10:40:45.334-0500

Hey, these patches don't immediately look too problematic, but is this saying that both of these patches are required or that just the second solves the problem?

By: Michael L. Young (elguero) 2011-07-18 10:47:22.539-0500

The second patch would be the one to use.

I created the first one based on a bt, but that only solved a message being sent from one specific function.  Therefore, there would still be the potential for other segfaults from other calling functions.  So, the second patch should cover all calling functions trying to send messages.

By: Jonathan Rose (jrose) 2011-08-24 16:14:40.747-0500

Hey, sorry for leaving this issue alone for so long.  Anyway, I'm still a little bewildered by the use of jabber within Asterisk... pubsub in particular and I was wondering what exactly one does to go about "publishing device states" via XMPP.  I saw this article by Malcolm Davenport describing this a bit, with something similar to this:

exten => inuse,1,Set(DEVICE_STATE(Custom:mystate)=INUSE)
exten => not_inuse,1,Set(DEVICE_STATE(Custom:mystate)=NOT_INUSE)

But I must be missing some critical details since I'm not seeing any jabber debugging coming out of using those.

Did get Openfire setup and connectable and tested in a number of ways and also have created some nodes which show up in jabber list nodes for my jabber user...

By: Michael L. Young (elguero) 2011-08-25 11:02:15.832-0500

Yep, it takes a little trial and error to get it working.

I think I used the section in the latest Asterisk book on distributed device states using xmpp to help play around with this.  http://ofps.oreilly.com/titles/9780596517342/asterisk-DeviceStates.html

I am using ejabberd as an xmpp server.  If you need any extra details, let me know.

By: Jonathan Rose (jrose) 2011-08-25 13:35:38.129-0500

Fortunately, I managed to figure it out by tinkering with it today...  well, mostly.  I got to the point of being able to publish the device states, just not to the point of actually reading them on the receiving end (I'll follow that link the rest of the way a little later).  Regardless, it was enough to test this bug you were pointing out (segfault replicated) and the patch that goes with it, and I'd say it seems appropriate.  I'll be committing this shortly.

Thanks for your contribution.

By: Leif Madsen (lmadsen) 2011-09-26 09:18:57.141-0500

Reopened issue per IRC.

By: Leif Madsen (lmadsen) 2011-09-26 09:20:51.535-0500

Actually sorry, I'm going to close this and request that a new issue be opened for the person on IRC to report again. I'll link here when I have a new issue.

By: Jonathan Rose (jrose) 2011-10-20 15:15:58.637-0500

I'm reopening this issue because well... first of all, we unsolved it.  Secondly I think I know a good way to fix it, and because I'm pretty sure stuff related to this is affecting google voice calls.

By: Jonathan Rose (jrose) 2011-10-21 15:59:48.932-0500

Alright, I've dived into libiksemel a little and determined that the iksparser used for iks_send_raw is lacking transport data and I've come up with a bad little patch involving a wrapper for iks_send_raw for mitigating the problem safely, but well, it's not super ideal.  Basically I'm pulling   At the moment I'm still pouring over libiksemel's documentation trying to figure out the preferred means of guaranteeing our connection is still good before calling iks_send_raw.  Basically I'm using iks_user_data to get the stream data out of the iksparser and using that to check the status of the transport, which if it's null causes this crash.  If I can't come up with anything better before Monday I'll go ahead and post that in this issue.

By: Joshua C. Colp (jcolp) 2012-07-17 11:32:34.376-0500

Fixed in trunk as of revision 370152.

By: Alec Davis (alecdavis) 2012-08-29 16:45:40.378-0500

Not fixed in SVN-branch-1.8-r358530M

Attaching gdb290812.txt

By: JoshE (n8ideas) 2012-10-13 17:17:53.383-0500

Seeing what appears to be the identical issue on Asterisk 10 as well.  Any ideas on a fix timeline or workaround for this?

By: SImone Freddio (siouxes) 2012-10-24 14:36:48.167-0500

i guys, i have tried to adding a simple check on aji_publish_device_state and on my system it seems to work well. i can't attach the patch, how can i share my code with you? cut&paste ?

By: Michael L. Young (elguero) 2012-10-24 14:48:24.342-0500

You need to sign a contributor's license first and await approval.  Then you can attach a file by selecting "Attach files" under the "More Actions" menu.

I am curious what kind of check you added.  The first patch, [^res_jabber-segfault-pubsub-not-connected.patch], attempted to add a check to the same function but through testing it was discovered that this was not enough to solve the problem.

By: SImone Freddio (siouxes) 2012-10-24 17:54:22.634-0500

Hi Michael,

i have modified the funtion aji_devstate_cb in this way (cut&paste causes some garbled tabs)

{noformat}
       if (client->state == AJI_CONNECTED) {
               aji_publish_device_state(client, device, device_state);
       } else {
               ast_log(LOG_DEBUG, "Can't publish device state, client is not connected\n");
       }
{noformat}

BR Simone

By: Michael L. Young (elguero) 2012-10-24 20:24:28.166-0500

SImone, I edited your post to display better.  Unfortunately I don't think that is enough to fix the real problem.  It essentially does what the first patch I mentioned above does.  There are other parts of the code that could trigger the segfault, as I found out.

By: Stefan Schmidt (schmidts) 2013-01-09 01:34:32.965-0600

i have added asterisk 10 also to this problem, cause we were able to reproduce this problem with 10.11.1

By: Sébastien Couture (sysreq) 2014-01-13 21:25:37.768-0600

I have experienced this issue under 1.8.25.0. I have applied patch #2, and in my case, it seems to prevent Asterisk from segfault'ing.

By: Corey Farrell (coreyfarrell) 2017-10-11 13:36:13.592-0500

res_jabber no longer exists in any currently supported version of Asterisk. If you haven't already you should switch to res_xmpp / chan_motif.  res_xmpp has a conditional to protect against this crash.