summaryrefslogtreecommitdiff
path: root/main
AgeCommit message (Collapse)Author
2017-06-07Merge "channel: ast_write frame wrongly freed after call to audiohooks" into 13Jenkins2
2017-06-06Merge "format: Reintroduce smoother flags" into 13Jenkins2
2017-06-05channel: ast_write frame wrongly freed after call to audiohooksKevin Harwell
ASTERISK-26419 introduced a bug when calling ast_audiohook_write_list in ast_write. It would free the frame given to ast_write if the frame returned by ast_audiohook_write_list was different than the given one. The frame give to ast_write should never be freed within that function. It is the caller's resposibility to free the frame after writing (or when it its done with it). By freeing it within ast_write this of course led to some memory corruption problems. This patch makes it so the frame given to ast_write is no longer freed within the function. The frame returned by ast_audiohook_write_list is now subsequently used in ast_write and is freed later. It is freed either after translate if the frame returned by translate is different, or near the end of ast_write prior to function exit. ASTERISK-26973 #close Change-Id: I463d4ac3b736ced95de986ee74a489c7c7ab103b
2017-05-31pbx_builtin: Properly handle hangup during BackgroundSean Bright
Before this patch, when a user hung up during a Background, we would stuff 0xff into a char and attempt a dialplan lookup of it. This caused problems for some realtime engines which interpreted the value as the beginning of an invalid UTF-8 sequence. ASTERISK-19291 #close Reported by: Andrew Nowrot Change-Id: I8ca6da93252d61c76ebdb46a4aa65e73ca985358
2017-05-31channel / app_meetme: Fix parentheses.Joshua Colp
ASTERISK-27025 Change-Id: Id736b0aa4ec6b6b0f04663d64fa8d151f81fdbed
2017-05-30format: Reintroduce smoother flagsSean Bright
In review 4843 (ASTERISK-24858), we added a hack that forced a smoother creation when sending signed linear so that the byte order was adjusted during transmission. This was needed because smoother flags were lost during the new format work that was done in Asterisk 13. Rather than rolling that same hack into res_rtp_multicast, re-introduce smoother flags so that formats can dictate their own options. Change-Id: I77b835fba0e539c6ce50014a984766f63cab2c16
2017-05-26manager: Clear the flag on the other channel.Joshua Colp
During the channel flag audit an incorrect change was done. The flag should be cleared on the second channel. ASTERISK-26469 Change-Id: I770c5a389550a2fb5a6ade942fccbb2e1d9199c8
2017-05-26Merge "asterisk: Audit locking of channel when manipulating flags." into 13Jenkins2
2017-05-24unittests: Add a unit test that causes a SEGV and...George Joseph
...that can only be run by explicitly calling it with 'test execute category /DO_NOT_RUN/ name RAISE_SEGV' This allows us to more easily test CI and debugging tools that should do certain things when asterisk coredumps. To allow this a new member was added to the ast_test_info structure named 'explicit_only'. If set by a test, the test will be skipped during a 'test execute all' or 'test execute category ...'. Change-Id: Ia3a11856aae4887df9a02b6b081cc777b36eb6ed
2017-05-16asterisk: Audit locking of channel when manipulating flags.Joshua Colp
When manipulating flags on a channel the channel has to be locked to guarantee that nothing else is also manipulating the flags. This change introduces locking where necessary to guarantee this. It also adds helper functions that manipulate channel flags and lock to reduce repeated code. ASTERISK-26789 Change-Id: I489280662dba0f4c50981bfc5b5a7073fef2db10
2017-05-11Merge "logger: Added logger_queue_limit to the configuration options." into 13Jenkins2
2017-05-11Merge "tcptls: Improve error messages for TLS connections." into 13Jenkins2
2017-05-11Merge "Prevent Undefined Capath Crash" into 13Jenkins2
2017-05-09tcptls: Improve error messages for TLS connections.Joshua Colp
This change uses the functions provided by OpenSSL to query and better construct error messages for situations where the connection encounters a problem. ASTERISK-26606 Change-Id: I7ae40ce88c0dc4e185c4df1ceb3a6ccc198f075b
2017-05-09Prevent Undefined Capath CrashJoshua Elson
It is possible to initialize a valid config without a capath or cafile definition. This will cause a crash on a reload. This fix ensures capath is always allocated. ASTERISK-26983 #close Change-Id: I63ff715d9d9023427543a5b8a4ba7b0d82533c12
2017-05-08logger: Added logger_queue_limit to the configuration options.George Joseph
All log messages go to a queue serviced by a single thread which does all the IO. This setting controls how big that queue can get (and therefore how much memory is allocated) before new messages are discarded. The default is 1000. Should something go bezerk and log tons of messages in a tight loop, this will prevent memory escalation. When the limit is reached, a WARNING is logged to that effect and messages are discarded until the queue is empty again. At that time another WARNING will be logged with the count of discarded messages. There's no "low water mark" for this queue because the logger thread empties the entire queue and processes it in 1 batch before going back and waiting on the queue again. Implementing a low water mark would mean additional locking as the thread processes each message and it's not worth it. A "test" was added to test_logger.c but since the outcome is non-deterministic, it's really just a cli command, not a unit test. Change-Id: Ib4520c95e1ca5325dbf584c7989ce391649836d1
2017-05-08Merge "netsock2.c: Made get/set addr port avoid potential uninitialized ↵Joshua Colp
memory." into 13
2017-05-08Merge "bridge: Fix returning to dialplan when executing Bridge() from AMI." ↵Joshua Colp
into 13
2017-05-05netsock2.c: Made get/set addr port avoid potential uninitialized memory.Richard Mudgett
Change-Id: I532052bd7cd95a4b3565485fc01e2a1ea07ee647
2017-05-04app_confbridge: Fix reference to cfg in menu_template_handlerGeorge Joseph
menu_template_handler wasn't properly accounting for the fact that it might be called both during a load/reload (which isn't really valid but not prevented) and by a dialplan function. In both cases it was attempting to use the "pending" config which wasn't valid in the latter case. aco_process_config is also partly to blame because it wasn't properly cleaning "pending" up when a reload was done and no changes were made. Both of these contributed to a crash if CONFBRIDGE(menu,template) was called in a dialplan after a reload. * aco_process_config now sets info->internal->pending to NULL after it unrefs it although this isn't strictly necessary in the context of this fix. * menu_template_handler now uses the "current" config and silently ignores any attempt to be called as a result of someone uses the "template" parameter in the conf file. Luckily there's no other place in the codebase where aco_pending_config is used outside of aco_process_config. ASTERISK-25506 #close Reported-by: Frederic LE FOLL Change-Id: Ib349a17d3d088f092480b19addd7122fcaac21a7
2017-05-04bridge: Fix returning to dialplan when executing Bridge() from AMI.Joshua Colp
When using the Bridge AMI action on the same channel multiple times it was possible for the channel to return to the wrong location in the dialplan if the other party hung up. This happened because the priority of the channel was not preserved across each action invocation and it would fail to move on to the next priority in other cases. This change makes it so that the priority of a channel is preserved when taking control of it from another thread and it is incremented as appropriate such that the priority reflects where the channel should next be executed in the dialplan, not where it may or may not currently be. The Bridge AMI action was also changed to ensure that it too starts the channels at the next location in the dialplan. ASTERISK-24529 Change-Id: I52406669cf64208aef7252a65b63ade31fbf7a5a
2017-04-29rtp_engine.c: Fix deadlock potential copying RTP payload maps.Richard Mudgett
There is a theoretical potential to deadlock in ast_rtp_codecs_payloads_copy() because it locks two different ast_rtp_codecs locks. It is theoretical because the callers of the function are either copying between a local ast_rtp_codecs struct and a RTP instance of the ast_rtp_codecs struct. Or they are copying between the caller and callee channel RTP instances before initiating the call to the callee. Neither of these situations could actually result in a deadlock because there cannot be another thread involved at the time. * Add deadlock avoidance code to ast_rtp_codecs_payloads_copy() since it locks two ast_rtp_codecs locks to perform a copy. This only affects v13 since this deadlock avoidance code is already in newer branches. Change-Id: I1aa0b168f94049bd59bbd74a85bd1e78718f09e5
2017-04-27Merge "frame: Better handle interpolated frames." into 13Jenkins2
2017-04-26frame: Better handle interpolated frames.Joshua Colp
Interpolated frames are frames which contain a number of samples but have no actual data. Audiohooks did not handle this case when translating an incoming frame into signed linear. It assumed that a frame would always contain media when it may not. If this occurs audiohooks will now immediately return and not act on the frame. As well for users of ast_trans_frameout the function has been changed to be a bit more sane and ensure that the data pointer on a frame is set to NULL if no data is actually on the frame. This allows the various spots in Asterisk that check for an interpolated frame based on the presence of a data pointer to work as expected. ASTERISK-26926 Change-Id: I7fa22f631fa28d540722ed789ce28e84c7f8662b
2017-04-25cleanup: Fix fread() and fwrite() error handlingSean Bright
Cleaned up some of the incorrect uses of fread() and fwrite(), mostly in the format modules. Neither of these functions will ever return a value less than 0, which we were checking for in some cases. I've introduced a fair amount of duplication in the format modules, but I plan to change how format modules work internally in a subsequent patch set, so this is simply a stop-gap. Change-Id: I8ca1cd47c20b2c0b72088bd13b9046f6977aa872
2017-04-24core: Use eventfd for alert pipes on Linux when possibleSean Bright
The primary win of switching to eventfd when possible is that it only uses a single file descriptor while pipe() will use two. This means for each bridge channel we're reducing the number of required file descriptors by 1, and - if you're using timerfd - we also now have 1 less file descriptor per Asterisk channel. The API is not ideal (passing int arrays), but this is the cleanest approach I could come up with to maintain API/ABI. I've also removed what I believe to be an erroneous code block that checked the non-blocking flag on the pipe ends for each read. If the file descriptor is 'losing' its non-blocking mode, it is because of a bug somewhere else in our code. In my testing I haven't seen any measurable difference in performance. Change-Id: Iff0fb1573e7f7a187d5211ddc60aa8f3da3edb1d
2017-04-21Merge "pbx: Use same thread if AST_OUTGOING_WAIT_COMPLETE specified" into 13George Joseph
2017-04-19pbx: Use same thread if AST_OUTGOING_WAIT_COMPLETE specifiedSean Bright
Both ast_pbx_outgoing_app() and ast_pbx_outgoing_exten() cause the core to spawn a new thread to perform the dial. When AST_OUTGOING_WAIT_COMPLETE is passed to these functions, the calling thread will be blocked until the newly created channel has been hung up. After this patch, we run the dial on the current thread rather than spawning a new one. The only in-tree code that passes AST_OUTGOING_WAIT_COMPLETE is pbx_spool, so you should see reduced thread usage if you are using .call files. Change-Id: I512735d243f0a9da2bcc128f7a96dece71f2d913
2017-04-19rtp_engine/res_rtp_asterisk: Fix RTP struct reentrancy crashes.Richard Mudgett
The struct ast_rtp_instance has historically been indirectly protected from reentrancy issues by the channel lock because early channel drivers held the lock for really long times. Holding the channel lock for such a long time has caused many deadlock problems in the past. Along comes chan_pjsip/res_pjsip which doesn't necessarily hold the channel lock because sometimes there may not be an associated channel created yet or the channel pointer isn't available. In the case of ASTERISK-26835 a pjsip serializer thread was processing a message's SDP body while another thread was reading a RTP packet from the socket. Both threads wound up changing the rtp->rtcp->local_addr_str string and interfering with each other. The classic reentrancy problem resulted in a crash. In the case of ASTERISK-26853 a pjsip serializer thread was processing a message's SDP body while another thread was reading a RTP packet from the socket. Both threads wound up processing ICE candidates in PJPROJECT and interfering with each other. The classic reentrancy problem resulted in a crash. * rtp_engine.c: Make the ast_rtp_instance_xxx() calls lock the RTP instance struct. * rtp_engine.c: Make ICE and DTLS wrapper functions to lock the RTP instance struct for the API call. * res_rtp_asterisk.c: Lock the RTP instance to prevent a reentrancy problem with rtp->rtcp->local_addr_str in the scheduler thread running ast_rtcp_write(). * res_rtp_asterisk.c: Avoid deadlock when local RTP bridging in bridge_p2p_rtp_write() because there are two RTP instance structs involved. * res_rtp_asterisk.c: Avoid deadlock when trying to stop scheduler callbacks. We cannot hold the instance lock when trying to stop a scheduler callback. * res_rtp_asterisk.c: Remove the lock in struct dtls_details and use the struct ast_rtp_instance ao2 object lock instead. The lock was used to synchronize two threads to prevent a race condition between starting and stopping a timeout timer. The race condition is no longer present between dtls_perform_handshake() and __rtp_recvfrom() because the instance lock prevents these functions from overlapping each other with regards to the timeout timer. * res_rtp_asterisk.c: Remove the lock in struct ast_rtp and use the struct ast_rtp_instance ao2 object lock instead. The lock was used to synchronize two threads using a condition signal to know when TURN negotiations complete. * res_rtp_asterisk.c: Avoid deadlock when trying to stop the TURN ioqueue_worker_thread(). We cannot hold the instance lock when trying to create or shut down the worker thread without a risk of deadlock. This patch exposed a race condition between a PJSIP serializer thread setting up an ICE session in ice_create() and another thread reading RTP packets. * res_rtp_asterisk.c:ice_create(): Set the new rtp->ice pointer after we have re-locked the RTP instance to prevent the other thread from trying to process ICE packets on an incomplete ICE session setup. A similar race condition is between a PJSIP serializer thread resetting up an ICE session in ice_create() and the timer_worker_thread() processing the completion of the previous ICE session. * res_rtp_asterisk.c:ast_rtp_on_ice_complete(): Protect against an uninitialized/null remote_address after calling update_address_with_ice_candidate(). * res_rtp_asterisk.c: Eliminate the chance of ice_reset_session() destroying and setting the rtp->ice pointer to NULL while other threads are using it by adding an ao2 wrapper around the PJPROJECT ice pointer. Now when we have to unlock the RTP instance object to call a PJPROJECT ICE function we will hold a ref to the wrapper. Also added some rtp->ice NULL checks after we relock the RTP instance and have to do something with the ICE structure. ASTERISK-26835 #close ASTERISK-26853 #close Change-Id: I780b39ec935dcefcce880d50c1a7261744f1d1b4
2017-04-12modules: change module LOAD_FAILUREs to LOAD_DECLINESGeorge Joseph
In all non-pbx modules, AST_MODULE_LOAD_FAILURE has been changed to AST_MODULE_LOAD_DECLINE. This prevents asterisk from exiting if a module can't be loaded. If the user wishes to retain the FAILURE behavior for a specific module, they can use the "require" or "preload-require" keyword in modules.conf. A new API was added to logger: ast_is_logger_initialized(). This allows asterisk.c/check_init() to print to the error log once the logger subsystem is ready instead of just to stdout. If something does fail before the logger is initialized, we now print to stderr instead of stdout. Change-Id: I5f4b50623d9b5a6cb7c5624a8c5c1274c13b2b25
2017-04-12Merge changes from topics 'ASTERISK-26890', 'ASTERISK-26851' into 13Joshua Colp
* changes: stun.c: Fix ast_stun_request() erratic timeout. sorcery.c: Speed up ast_sorcery_retrieve_by_id() res_pjsip: Fix pointer use after unref. res_pjsip_sdp_rtp.c: Don't use deprecated transport struct member.
2017-04-11stun.c: Fix ast_stun_request() erratic timeout.Richard Mudgett
If ast_stun_request() receives packets other than a STUN response then we could conceivably never exit if we continue to receive packets with less than three seconds between them. * Fix poll timeout to keep track of the time when we sent the STUN request. We will now send a STUN request every three seconds regardless of how many other packets we receive while waiting for a response until we have completed three STUN request transmission cycles. Change-Id: Ib606cb08585e06eb50877f67b8d3bd385a85c266
2017-04-11sorcery.c: Speed up ast_sorcery_retrieve_by_id()Richard Mudgett
Return early if ast_sorcery_retrieve_by_id() is not passed an id to find. Also eliminated the RAII_VAR() usage in the function. Change-Id: I871dbe162a301b5ced8b4393cec27180c7c6b218
2017-04-11tcptls.c: Cleanup TCP/TLS listener thread on abnormal exit.Richard Mudgett
Temporarily running out of file descriptors should not terminate the listener thread. Otherwise, when there becomes more file descriptors available, nothing is listening. * Added EMFILE exception to abnormal thread exit. * Added an abnormal TCP/TLS listener exit error message. * Closed the TCP/TLS listener socket on abnormal exit so Asterisk does not appear dead if something tries to connect to the socket. ASTERISK-26903 #close Change-Id: I10f2f784065136277f271159f0925927194581b5
2017-04-04CDR: Protect from data overflow in ast_cdr_setuserfield.Corey Farrell
ast_cdr_setuserfield wrote to a fixed length field using strcpy. This could result in a buffer overrun when called from chan_sip or func_cdr. This patch adds a maximum bytes written to the field by using ast_copy_string instead. ASTERISK-26897 #close patches: 0001-CDR-Protect-from-data-overflow-in-ast_cdr_setuserfie.patch submitted by Corey Farrell (license #5909) Change-Id: Ib23ca77e9b9e2803a450e1206af45df2d2fdf65c
2017-03-31Merge "build: Fix deb build issues with fakeroot" into 13George Joseph
2017-03-30build: Fix deb build issues with fakerootWalter Doekes
If DESTDIR is set, don't call ldconfig. Assume that DESTDIR is used to create a binary archive. The ldconfig call should be delegated to the archive postinst script. This fixes the case where fakeroot wraps 'make install' causing $EUID to be 0 even though it doesn't have permission to call ldconfig. The previous logic in configure.ac to detect and correct libdir has been removed as it was not completely accurate. CentOS 64-bit users should again specifiy --libdir=/usr/lib64 when configuring to prevent install to /usr/lib. Updated Makefile:check-old-libdir to check for orphans in lib64 when installing to lib as well as orphans in lib when installing to lib64. Updated Makefile and main/Makefile uninstall targets to remove the orphans using the new logic. ASTERISK-26705 Change-Id: I51739d4a03e60bff38be719b8d2ead0007afdd51
2017-03-30astobj2: Prevent potential deadlocks with ao2_global_obj_releaseSean Bright
The ao2_global_obj_release() function holds an exclusive lock on the global object while it is being dereferenced. Any destructors that run during this time that call ao2_global_obj_ref() will deadlock because a read lock is required. Instead, we make the global object inaccessible inside of the write lock and only dereference it once we have released the lock. This allows the affected destructors to fail gracefully. While this doesn't completely solve the referenced issue (the error message about not being able to create an IQ continues to be shown) it does solve the backtrace spew that accompanied it. ASTERISK-21009 #close Reported by: Marcello Ceschia Change-Id: Idf40ae136b5070dba22cb576ea8414fbc9939385
2017-03-29Merge "srtp: Allow zero as tag value for a sRTP Crypto Suite." into 13Joshua Colp
2017-03-29srtp: Allow zero as tag value for a sRTP Crypto Suite.Alexander Traud
ASTERISK-25490 #close Change-Id: I1c5fc0942c33c96d62b24203aad0f1e1a1a0131f
2017-03-27core: Remove embedded module supportSean Bright
This has not worked for some time and is no longer actively maintained. Change-Id: I5110b0db69c152761b58fa025cb0a53b0e544d99
2017-03-24Merge "cdr: Allow setting of user field from 'h' extension" into 13zuul
2017-03-24Merge "audiohook.c: Lost RTP packets lead to out-of-sync MixMonitor." into 13zuul
2017-03-22Merge "res_pjsip_messaging: Check URI type before dereferencing" into 13zuul
2017-03-22cdr: Allow setting of user field from 'h' extensionSebastian Gutierrez
The CDR code previously did not allow the user field to be set from the 'h' extension in the dialplan. This change removes that limitation and allows it to be set. ASTERISK-26818 Change-Id: I0fed8a79b5e408bac4e30542b8f33a61c5ed9aa6
2017-03-21Merge "autochan/mixmonitor/chanspy: Fix unsafe channel locking and ↵zuul
references." into 13
2017-03-21res_pjsip_messaging: Check URI type before dereferencingSean Bright
We aren't validating that the URI we just parsed is a SIP/SIPS one before trying to access the user, host, and port members of a possibly uninitialized structure. Also update the MessageSend documentation to indicate what 'from' formats are accepted. ASTERISK-26484 #close Reported by: Vinod Dharashive Change-Id: I476b5cc5f18a7713d0ee945374f2a1c164857d30
2017-03-20audiohook.c: Lost RTP packets lead to out-of-sync MixMonitor.Aaron An
Fixed a bug in function "ast_audiohook_write_frame" that checked the variable other_factory_samples and only flushed the factories, so they would be in sync, when other_factory_samples > 0. When there is not any rtp incoming the variable other_factory_samples will be 0, and although the result of "our_factory_ms - other_factory_ms" may be very large, this led to the record file not syncing. ASTERISK-26875 #close Reported-by: Aaron An Tested-by: Aaron An Change-Id: Ia4d890fb8fc1636a7188502bab35f555685aea22
2017-03-20thread safety: Don't use getprotobyname()Sean Bright
POSIX does not require getprotobyname() to be thread safe and some implementations use static memory which causes issues when multiple threads are used. Further, our usage of it today is just to ultimately get IPPROTO_TCP for calls to setsockopt(). So instead we just use IPPROTO_TCP directly. Change-Id: I2e14e58674808f7ce99b2f5e900d0f90d0d8da48
2017-03-15Merge "pbx.c: Fix crash from malformed exten pattern." into 13zuul