summaryrefslogtreecommitdiff
path: root/res
AgeCommit message (Collapse)Author
2015-07-08res_rtp_asterisk: Ensure DTLS timeout timer is -1 if DTLS is not used.Joshua Colp
This change fixes a bug where the DTLS timeout timer would be initialized to 0 if DTLS was not used for an RTP session. ASTERISK-25103 Change-Id: If8d26bb054f1d300838850da5b8db9044c2fe2ac
2015-07-07Merge "res_pjsip_mwi.c: Use safer loop coding in ↵Matt Jordan
mwi_subscription_mailboxes_str()." into 13
2015-07-07Merge "res_pjsip_mwi.c: Fix MWI subscription memory corruption crash." into 13Matt Jordan
2015-07-07Merge "PJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error." ↵Joshua Colp
into 13
2015-07-07Merge topic 'res_pjsip_mwi_cleanups' into 13Joshua Colp
* changes: res_pjsip_mwi.c: Eliminate a simple RAII_VAR. res_pjsip_mwi.c: Fix mid-line log message line breaks.
2015-07-07Merge "PJSIP FAX: Fix T.38 automatic reject timer NULL channel pointer ↵Joshua Colp
dereferences." into 13
2015-07-07Merge "res_pjsip_t38.c: Fix always false if test." into 13Joshua Colp
2015-07-07Merge "res_pjsip: Need to use the same serializer for a pjproject SIP ↵Joshua Colp
transaction." into 13
2015-07-07Merge "res/res_http_websocket: Don't send HTTP response fragmented." into 13Joshua Colp
2015-07-07res_rtp_asterisk: Prevent simultaneous access to DTLS SSL context.Joshua Colp
This change moves logic for setting up the DTLS SSL contexts to when the SDP is done being processed instead of when ICE negotiation completes. It also stops handshakes from being initiated when we are acting as a server. Manipulating the SSL context when ICE negotiation has completed is problematic as the SSL context is not protected and if acting as a client the remote side may have started DTLS negotiation already. The retransmission timeout timer code has also been split up and simplified some. Both RTP and RTCP now have their own timers and the points at which the timer is stopped and started is now more specific. When a packet is sent the timer is started. When a response is received but before it is processed the timer is stopped. This provides a guarantee that the timeout is not occurring while the response is processed. ASTERISK-22805 #close ASTERISK-24550 #close ASTERISK-24651 #close ASTERISK-24832 #close ASTERISK-25103 #close ASTERISK-25127 #close Change-Id: Ib75ea2546f29d6efc3d2d37c58df6986c7bd9b91
2015-07-06res_pjsip_t38.c: Fix always false if test.Richard Mudgett
Calling t38_change_state() sets the t38 state so it makes little sense to then check the state right after the call for something else. * Made the code in t38_interpret_parameters() reject or exit T.38 mode as intended but not implemented. Change-Id: Ib281263a6ed44da9448132c4e6df1e183b8a3df2
2015-07-06res_pjsip_mwi.c: Use safer loop coding in mwi_subscription_mailboxes_str().Richard Mudgett
Change-Id: I6f39d809a6d1b47b35bb32b298f5a12f35d6f907
2015-07-06res_pjsip_mwi.c: Eliminate a simple RAII_VAR.Richard Mudgett
Change-Id: Ib1843f81e826a6c760c424c88eb70c350d9d61da
2015-07-06res_pjsip_mwi.c: Fix mid-line log message line breaks.Richard Mudgett
* Add create_mwi_subscriptions_for_endpoint() doxygen comment. Change-Id: I3c3f921f4ec749fb65b62d2f6fa0d4d1888b94e2
2015-07-06res_pjsip_mwi.c: Fix MWI subscription memory corruption crash.Richard Mudgett
MWI subscriptions can crash or corrupt memory when using the subscription datastore to access the MWI subscription object because the datastore is not holding a reference to the object. * Give the subscription datastore a ref to the MWI subscription object. It is unfortunate that the ref causes a circular ref chain that must be explicitly broken to allow the memory to get released. The loop is broken when the subscription is shutdown and if the subscription setup fails. ASTERISK-25168 #close Reported by: Carl Fortin Change-Id: Ice4fa823f138ff10a6c74d280699c41a82836d4f
2015-07-06PJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error.Richard Mudgett
When res_pjsip body generator modules were generating XML or XPIDF response bodies, there was a chance that the generated body would be the exact size of the supplied buffer. Adding the nul string terminator would then write beyond the end of the buffer and potentially corrupt memory. * Fix MALLOC_DEBUG high fence violations caused by adding a nul string terminator on the end of a buffer for XML or XPIDF response bodies. * Made calls to pj_xml_print() safer if the XML prolog is requested. Due to a bug in pjproject, the return value could be -1 _or_ AST_PJSIP_XML_PROLOG_LEN if the supplied buffer is not large enough. * Updated the doxygen comment of AST_PJSIP_XML_PROLOG_LEN to describe the return value of pj_xml_print() when the supplied buffer is not large enough. ASTERISK-25168 Reported by: Carl Fortin Change-Id: Id70e1d373a6a2b2bd9e678b5cbc5e55b308981de
2015-07-06PJSIP FAX: Fix T.38 automatic reject timer NULL channel pointer dereferences.Richard Mudgett
When a caller calls a FAX number and then hangs up right after the call is answered then the T.38 re-INVITE automatic reject timer may still be running after the channel goes away. * Added session NULL channel checks on the code paths that get executed by t38_automatic_reject() to prevent a crash when the T.38 re-INVITE automatic reject timer expires. ASTERISK-25168 Reported by: Carl Fortin Change-Id: I07b6cd23815aedce5044f8f32543779e2f7a2403
2015-07-06res_pjsip: Need to use the same serializer for a pjproject SIP transaction.Richard Mudgett
All send/receive processing for a SIP transaction needs to be done under the same threadpool serializer to prevent reentrancy problems inside pjproject and res_pjsip. * Add threadpool API call to get the current serializer associated with the worker thread. * Pick a serializer from a pool of default serializers if the caller of res_pjsip.c:ast_sip_push_task() does not provide one. This is a simple way to ensure that all outgoing SIP request messages are processed under a serializer. Otherwise, any place where a pushed task is done that would result in an outgoing out-of-dialog request would need to be modified to supply a serializer. Serializers from the default serializer pool are picked in a round robin sequence for simplicity. A side effect is that the default serializer pool will limit the growth of the thread pool from random tasks. This is not necessarily a bad thing. * Made pjsip_distributor.c save the thread's serializer name on the outgoing request tdata struct so the response can be processed under the same serializer. This is a cherry-pick from master. **** ASTERISK-25115 Change-Id: Iea71c16ce1132017b5791635e198b8c27973f40a NOTE: session_inv_on_state_changed() is disassociating the dialog from the session when the invite dialog becomes PJSIP_INV_STATE_DISCONNECTED. Unfortunately this is a tad too soon because our BYE request transaction has not completed yet. ASTERISK-25183 #close Reported by: Matt Jordan Change-Id: I8bad0ae1daf18d75b8c9e55874244b7962df2d0a
2015-07-04res/res_http_websocket: Don't send HTTP response fragmented.Joshua Colp
This change makes it so that when accepting a WebSocket connection the HTTP response is sent as one packet instead of fragmented. Browsers don't like it when you send it fragmented. ASTERISK-25103 Change-Id: I9b82c4ec2949b0bce692ad0bf6f7cea9709e7f69
2015-07-04Makefile: Remove coverage files on 'make clean'Matt Jordan
This patch updates a variety of Makefiles in Asterisk's build system to remove .gcda and .gcno files when 'make clean' is executed. These files are generated when '--enable-coverage' is passed to the Asterisk configure script. Change-Id: Ib70b41eea2ee2908885bff02e80faf9f40c84602
2015-07-02res_timing: Don't close FD 0 when out of open files.Walter Doekes
This fixes so a failure to get a timer file descriptor does not cascade to closing FD 0. On error, both res_timing_kqueue and res_timing_timerfd would call the destructor before setting the file handle. The file handle had been initialized to 0, causing FD 0 to be closed. This in turn, resulted in floods of "CLI>" messages and an unusable terminal. ASTERISK-19277 #close Reported by: Barry Chern For the 13 branch, this was already fixed. This patch only ensures that we do not attempt to close a negative file descriptor. Change-Id: I147d7e33726c6e5a2751928d56561494f5800350
2015-06-29res_sorcery_realtime: Fix leak of sorcery object type.Mark Michelson
This prevents a leak of a sorcery object type when realtime sorcery objects are retrieved by fields or when multiple objects are retrieved. The extent of this leak is that sorcery object types would be leaked. These are allocated whenever an object type is registered with sorcery, meaning that on module shutdown, these objects would be leaked. This could be problematic if many reloads were performed, but it is not as severe as if every sorcery object retrieved from realtime were being leaked. ASTERISK-25165 #close Reported by Corey Farrell Change-Id: I625c3b50eee4576670b7eeb013c81ad043b4b4f8
2015-06-29Merge "res_pjsip_nat: Adjust when contact should be rewritten." into 13Matt Jordan
2015-06-26res/res_corosync: Always decline module load, instead of failingMatt Jordan
Returns a 'failure' from the module load routine indicates to Asterisk that it should abort loading completely. This is rarely - in fact, really, never - a good option. Aborting load of Asterisk from a dynamic module implies that the core, and the rest of the dynamic modules, don't matter: we should abandon all processing. res_corosync is really not that important. This patch updates the module such that, if it fails to load, it politely declines (emitting ERROR messages along the way), and allows Asterisk to continue to function. Note that this issue was keeping Asterisk unit tests from running on certain build agents. Change-Id: I252249e81fb9b1a68e0da873f54f47e21d648f0f
2015-06-26res_pjsip_nat: Adjust when contact should be rewritten.Mark Michelson
A previous change made the contact only get rewritten if the dialog's route set was not marked frozen. Unfortunately, while the intent of this is correct, the dialog's route set actually gets marked as frozen earlier than expected, especially for UAS dialogs. Instead, the idea is that the contact needs to not be rewritten if there is a pre-existing route set on the dialog. This is now accomplished by checking the dialog's route set list instead of checking if the route set is frozen. Doing this causes some broken tests to begin passing again. ASTERISK-25196 Reported by Mark Michelson Change-Id: I525ab251fd40a52ede327a52a2810a56deb0529e
2015-06-26res_pjsip_outbound_registration.c: Add a serializer shutdown group.Richard Mudgett
The client_state objects contain a serializer used to send the outbound REGISTER messages. Once all those message transactions are complete then the module can shutdown. ASTERISK-24907 #close Reported by: Kevin Harwell Change-Id: Ibb2fe558f98190f2a06da830e0fadfa25516f547
2015-06-26Merge "threadpool, res_pjsip: Add serializer group shutdown API calls." into 13Matt Jordan
2015-06-26Merge "res_pjsip_outbound_registration.c: Fix ↵Matt Jordan
handle_client_state_destruction() refs" into 13
2015-06-26Merge "res_pjsip_outbound_registration.c: Use ↵Matt Jordan
ast_sorcery_object_unregister() API" into 13
2015-06-26Merge "res_pjsip_refer: Prevent sending duplicate headers." into 13Matt Jordan
2015-06-26Merge "res_pjsip_outbound_registration.c: Reorder load_module() and ↵Matt Jordan
unload_module()." into 13
2015-06-26res_pjsip_refer: Prevent sending duplicate headers.Mark Michelson
res_pjsip_refer will attempt to add Referred-By or Replaces headers to outbound INVITEs at times. If the INVITE gets challenged for authentication, then we will resend the INVITE. Prior to this patch, the Referred-By or Replaces header would be re-added to the outbound INVITE, resulting in duplicated headers. ASTERISK-25204 #close Reported by Mark Michelson Change-Id: I59fb5c08b4d253c0dba9ee3d3950b5025358222d
2015-06-26res_pjsip_nat: Rewrite route set when required.Mark Michelson
When performing some provider testing, the rewrite_contact option was interfering with proper construction of a route set when sending an ACK after receiving a 200 OK response to an INVITE. The initial INVITE was sent to address sip:foo. The 200 OK had a Contact header with URI sip:bar. In addition, the 200 OK had Record-Route headers for sip:baz and sip:foo, in that order. Since the Record-Route headers had the lr parameter, the result should have been: * Set R-URI of the ACK to sip:bar. * Add Route headers for sip:foo and sip:baz, in that order. However, the rewrite_contact option resulted in our rewriting the Contact header on the 200 OK to sip:foo. The result was: * R-URI remained sip:foo. * We added Route headers for sip:foo and sip:baz, in that order. The result was that sip:bar was not indicated in the ACK at all, so the far end never received our ACK. The call eventually dropped. The intention of rewrite_contact is to rewrite the most immediate destination of our SIP request to be the same address on which we received a request or response. In the case of processing a SIP response with Record-Route headers, this means that instead of rewriting the Contact header, we should instead rewrite the bottom-most Record-Route header. In the case of processing a SIP request with Record-Route headers, this means we rewrite the top-most Record-route header. Like when we rewrite the Contact header, we also ensure to update the dialog's route set if it exists. ASTERISK-25196 #close Reported by Mark Michelson Change-Id: I9702157c3603a2d0bd8a8215ac27564d366b666f
2015-06-25threadpool, res_pjsip: Add serializer group shutdown API calls.Richard Mudgett
A module trying to unload needs to wait for all serializers it creates and uses to complete processing before unloading. ASTERISK-24907 Reported by: Kevin Harwell Change-Id: I8c80b90f2f82754e8dbb02ddf3c9121e5e966059
2015-06-25res_pjsip_outbound_registration.c: Fix handle_client_state_destruction() refsRichard Mudgett
* handle_client_state_destruction() must always be passed a ref to client_state because it will always unref client_state. handle_registration_response() was not passing a client_state ref. * Made the final un-REGISTER message get sent normally using the pjproject register control structure in handle_client_state_destruction(). The previous code attempted to short circuit the response handling for the module to unload. That doesn't work for a couple reasons. One, pjsip_regc_send() may call the registered callback before it returns and unbalance the client_state ref count. Two, the registered callback handles any authentication for the un-REGISTER message. * Made the distinction between internal registration state and external registration status with sip_outbound_registration_status_str(). This is necessary to avoid altering documented AMI messages with internal changes. * Removed references to client_state->client outside of the serializer thread. When handle_client_state_destruction() destroys the pjproject register control structure that memory is freed and cannot be referenced anymore. These accesses were to provide information for debug and off-nominal warning messages. * In sip_outbound_registration_timer_cb() you should not access entry->id after unrefing client_state because the passed in entry is normally pointing to the timer entry in the client_state object. ASTERISK-24907 Reported by: Kevin Harwell Change-Id: Ia7b446d8644b6b4550ef5bea49527671de65183f
2015-06-25res_pjsip_outbound_registration.c: Use ast_sorcery_object_unregister() APIRichard Mudgett
The sorcery pjsip 'registration' config object needs to be destroyed on module unload. Otherwise, a reload of res_pjsip could try to use callbacks for a previously unloaded instance of the module provided by ast_sorcery_object_register() or one of the variants. Also, if res_pjsip_outbound_registration were subsequently reloaded, the sorcery config field objects would be registered in sorcery twice. ASTERISK-24907 Reported by: Kevin Harwell Change-Id: I304fad13dece2604af48353f6c6d9d5c7b064697
2015-06-25res_pjsip_outbound_registration.c: Reorder load_module() and unload_module().Richard Mudgett
It is best if the loading code creates and initializes the module's infrastructure before letting the system know of its existence. The unloading code needs to reverse the actions of the loading code and in the reverse order. ASTERISK-24907 Reported by: Kevin Harwell Change-Id: I5d151383e9787b5b60aa5e1627b10f040acdded4
2015-06-25Merge "res_pjsip_mwi: Set up unsolicited MWI upon registration." into 13Mark Michelson
2015-06-23res_pjsip_mwi: Set up unsolicited MWI upon registration.Joshua Colp
The res_pjsip_mwi previously required a reload to set up the proper subscriptions to allow unsolicited MWI to work. This change makes it so the act of registering will also cause this to occur. This is particularly useful if realtime is involved as no reload needs to occur within Asterisk to cause the MWI information to get sent. ASTERISK-25180 #close Change-Id: Id847b47de4b8b3ab8858455ccc2f07b0f915f252
2015-06-22res_pjsip_outbound_registration.c: Add missing line endings to CLI commandsRichard Mudgett
Change-Id: I39ae612746d892d2dbe86f3ff2d7027fa1da57f7
2015-06-22res_pjsip_outbound_registration.c: Eliminate simple RAII_VAR() usage.Richard Mudgett
Change-Id: I399cb9d61bbba706b48c98e0bf75e98984cd9a9e
2015-06-22res_pjsip_outbound_registration.c: Misc code cleanups.Richard Mudgett
* Break some long lines. * Fix doxygen comment. Change-Id: I8f12ba6822f84d5e7bb575280270cd7e2fefb305
2015-06-18Resolve race conditions involving Stasis bridges.Mark Michelson
This resolves two observed race conditions. First, a bit of background on what the Stasis application does: 1a Creates a stasis_app_control structure. This structure is linked into a global container and can be looked up using a channel's unique ID. 2a Puts the channel in an event loop. The event loop can exit either because the stasis_app_control structure has been marked done, or because of some other factor, such as a hangup. In the event loop, the stasis_app_control determines if any specific ARI commands need to be run on the channel and will run them from this thread. 3a Checks if the channel is bridged. If the channel is bridged, then ast_bridge_depart() is called since channels that are added to Stasis bridges are always imparted as departable. 4a Unlink the stasis_app_control from the container. When an ARI command is received by Asterisk, the following occurs 1b A thread is spawned to handle the HTTP request 2b The stasis_app_control(s) that corresponds to the channel(s) in the request is/are retrieved. If the stasis_app_control cannot be retrieved, then it is assumed that the channel in question has exited the Stasis app or perhaps was never in Stasis in the first place. 3b A command is queued onto the stasis_app_control, and the channel's event loop thread is signaled to run the command. 4b While most ARI commands do nothing further, some, such as adding or removing channels from a bridge, will block until the command they issued has been completed by the channel's event loop. The first race condition that is solved by this patch involves a crash that can occur due to faulty detection of the channel's bridged status in step 3a. What can happen is that in step 2a, the event loop may run the ast_bridge_impart() function to asynchronously place the channel into a bridge, then immediately exit the event loop because the channel has hung up. In step 3a, we would detect that the channel was not bridged and would not call ast_bridge_depart(). The reason that the channel did not appear to be bridged was that the depart_thread that is spawned by ast_bridge_impart() had not yet started. That is the thread where the channel is marked as being bridged. Since we did not call ast_bridge_depart(), the Stasis application would exit, and then the channel would be destroyed Then the depart_thread would start up and try to manipulate the destroyed channel, causing a crash. The fix for this is to switch from using ast_channel_is_bridged() to checking the NULLity of ast_channel_internal_bridge_channel() to determine if ast_bridge_depart() needs to be called. The channel's internal bridge_channel is set when ast_bridge_impart() is called and is NULLed by the call to ast_bridge_depart(). If the channel's internal bridge_channel is non-NULL, then the channel must have been imparted into the bridge and needs to be departed, even if the actual bridging operation has not yet started. By departing the channel when necessary, the thread that is running the Stasis application will block until the bridge gives the okay that the depart_thread has exited. The second race condition that is solved by this patch involves a leak of HTTP handler threads. The problem was that step 2b would successfully retrieve a stasis_app_control structure. Then step 2a would exit the channel from the event loop due to a hangup. Steps 3a and 4a would execute, and then finally steps 3b and 4b would. The problem is that at step 4b, when attempting to add a channel to a bridge, the thread would block forever since the channel would never execute the queued command since it was finished with the event loop. This meant that the HTTP handling thread would be leaked, along with any references that thread may have owned (in my case, I was seeing bridges leaked). The fix for this is to hone in better on when the channel has exited the event loop. The stasis_app_control structure has an is_done field that is now set at each point where the channel may exit the event loop. If step 2b retrieves a valid stasis_app_control structure but the control is marked as done, then the attempted operation exits immediately since there will be nothing to service the attempted command. ASTERISK-25091 #close Reported by Ilya Trikoz Change-Id: If66265b73b4c9f8f58599124d777fedc54576628
2015-06-16Parking: Add documentation for AMI ParkedCallSwap event.Mark Michelson
This event was added some time ago in order to clarify when a channel took the place of another channel in a parking lot. However, there was no XML documentation added for the event. This patch adds the XML documentation. ASTERISK-24900 #close Reported by Rusty Newton Change-Id: I4cfe7777c4b94bbff91c9221c6096a7a02a92eac
2015-06-15res_pjsip: Add option to force G.726 to be treated as AAL2 packed.Kevin Harwell
Some phones send g.726 audio packed for AAL2, which differs from what is recommended by RFC 3351. If Asterisk receives audio formatted as such when negotiating g.726 then it sounds a bit distorted. Added an option to res_pjsip_endpoint that allows g.726 negotiated audio to be treated as g.726 AAL2 packed. ASTERISK-25158 #close Reported by: Steve Pitts Change-Id: Ie7e21f75493d7fe53e75e12c971e72f5afa33615
2015-06-10res_pjsip_transport_websocket: Fix use-after-free bugs.Ivan Poddubny
This patch fixes use-after-free bugs caught by AddressSanitizer. 1. PJSIP transport manager may decide to destroy transport on its own. For example, when the contact registered via websocket has not renewed its registration in time. The transport was destoyed, but the websocket listener thread was still active until the socket closes, and then tried to call transport_shutdown on transport that has been freed. Also, the transport destructor accessed wstransport->rdata.tp_info.pool right after freeing memory that contained wstransport itself. This patch converts transport to an ao2 object, allowing it to be refcounted, so that it is available until both websocket listener and pjsip transport manager are finished with it. 2. The websocket listener deletes the last reference on websocket session when the tcp connection is closed, and it gets destroyed, but the transport manager may still use it, for example when disconnect happens in the middle of a SIP transaction. A new reference to websocket session has been added that is released with the transport to prevent this. ASTERISK-25096 #close Reported by: Josh Kitchens ASTERISK-24963 #close Reported by: Badalian Vyacheslav Change-Id: Idc0b63eb6e459c1ddfb2430127d34b3c4d8d373b
2015-06-05Merge "Fixes for OS X" into 13Joshua Colp
2015-06-03res_pjsip: Prevent access of NULL channels.Mark Michelson
It is possible to receive incoming requests or responses after the channel on an ast_sip_session has been destroyed and NULLed out. Handlers of these sorts of requests or responses need to be prepared for the possibility that the channel is NULL or else they could cause a crash. While several places have been amended to deal with NULL channels, there were still a couple of places that needed updating. res_pjsip_dtmf_info.c: When handling incoming INFO requests, we need to return early if there is no channel on the session. res_pjsip_session.c: When handling a 302 response, we need to stop the redirecting attempt if there is no channel on the session. ASTERISK-25148 #close reported by Mark Michelson Change-Id: Id1a75ffc3d0eaa168b0b28188fb54d6cf9fc47a9
2015-06-03res_pjsip/location: Fix ref leak in contact_apply_handlerGeorge Joseph
contact_apply_handler calls ast_res_pjsip_find_or_create_contact_status to force the creation of a contact_status object whenever a new contact is added but it didn't unref the returned object. Added an ao2_cleanup(status) to plug the leak. ASTERISK-25141 Change-Id: Icc1401cae142855a1abc86ab5179dfb3ee861c40 Reported-by: Corey Farrell
2015-06-02Fixes for OS XDavid M. Lee
* Add some type casting so tv_usec can really be a long, instead of some strange platform specific type. * Add some .dylib style files to .gitignore. * Switch from using -Xlinker to -Wl,. For [reasons unknown][], newer versions of GCC, when compiling the Homebrew formula for Asterisk, are not properly passing the -Xlinker options to the linker. Given that -Wl, does exactly the [same thing][], and does it properly, this patch changes the -Xlinker options to use -Wl, instead. [reasons unknown]: http://bit.ly/1SUbEYx [same thing]: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html Change-Id: Id5e6b3c6cc86282ea5fca630dc3991137c5bf4dd