Commit Graph

167 Commits

Author SHA1 Message Date
Richard Mudgett 97fcd6366d MALLOC_DEBUG: Fix some misuses of free() when MALLOC_DEBUG is enabled.
* There were several places in ARI where an external library was mallocing
memory that must always be released with free().  When MALLOC_DEBUG is
enabled, free() is redirected to the MALLOC_DEBUG version.  Since the
external library call still uses the normal malloc(), MALLOC_DEBUG
complains that the freed memory block is not registered and will not free
it.  These cases must use ast_std_free().

* Changed calls to asprintf() and vasprintf() to the equivalent
ast_asprintf() and ast_vasprintf() versions respectively.
........

Merged revisions 400270 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400271 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-10-02 17:12:49 +00:00
David M. Lee c2e6e1ef49 Fix DEBUG_THREADS when lock is acquired in __constructor__
This patch fixes some long-standing bugs in debug threads that were
exacerbated with recent Optional API work in Asterisk 12.

With debug threads enabled, on some systems, there's a lock ordering
problem between our mutex and glibc's mutex protecting its module list
(Ubuntu Lucid, glibc 2.11.1 in this instance). In one thread, the module
list will be locked before acquiring our mutex. In another thread, our
mutex will be locked before locking the module list (which happens in
the depths of calling backtrace()).

This patch fixes this issue by moving backtrace() calls outside of
critical sections that have the mutex acquired. The bigger change was to
reentrancy tracking for ast_cond_{timed,}wait, which wrongly assumed
that waiting on the mutex was equivalent to a single unlock (it actually
suspends all recursive locks on the mutex).

(closes issue ASTERISK-22455)
Review: https://reviewboard.asterisk.org/r/2824/
........

Merged revisions 398648 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 398649 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 398651 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@398652 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-09-09 20:13:40 +00:00
Richard Mudgett 46b9e5450f Fix memory corruption when trying to get "core show locks".
Review https://reviewboard.asterisk.org/r/2580/ tried to fix the mismatch
in memory pools but had a math error determining the buffer size and
didn't address other similar memory pool mismatches.

* Effectively reverted the previous patch to go in the same direction as
trunk for the returned memory pool of ast_bt_get_symbols().

* Fixed memory leak in ast_bt_get_symbols() when BETTER_BACKTRACES is
defined.

* Fixed some formatting in ast_bt_get_symbols().

* Fixed sig_pri.c freeing memory allocated by libpri when MALLOC_DEBUG is
enabled.

* Fixed __dump_backtrace() freeing memory from ast_bt_get_symbols() when
MALLOC_DEBUG is enabled.

* Moved __dump_backtrace() because of compile issues with the utils
directory.

(closes issue ASTERISK-22221)
Reported by: Matt Jordan

Review: https://reviewboard.asterisk.org/r/2778/
........

Merged revisions 397525 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 397528 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@397570 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-08-23 18:07:40 +00:00
Richard Mudgett a847e65b2c Fix utilities compilation/linking.
The horrid structure of the source in the utils directory strikes again.
Moved the _ast_mem_backtrace_buffer[] definition from the logical location
in utils.c to hashtab.c so the aelparse and conf2ael utilities can link.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396850 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-08-16 16:26:11 +00:00
Kinsey Moore a4ffa9f72b Improve sounds indexer CLI commands
This reworks the CLI commands used to access sounds information from
"sounds show[ soundid]" to "core show sounds" and
"core show sound <soundid>". This also reworks the "sounds reload" CLI
command to fall under normal module reloading ("module reload sounds").

Also, make trunk build when DEBUG_MALLOC is not enabled.

Review: https://reviewboard.asterisk.org/r/2745/
(closes issue ASTERISK-22141)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396829 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-08-16 12:20:59 +00:00
Walter Doekes c43e19e8e5 Prevent heap alloc functions from running out of stack space.
When asterisk has run out of memory (for whatever reason), the alloc
function logs a message. Logging requires memory. A recipe for
infinite recursion.

Stop the recursion by comparing the function call depth for sane values
before attempting another OOM log message.

Review: https://reviewboard.asterisk.org/r/2743/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396822 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-08-16 07:18:51 +00:00
Kinsey Moore 3f46d461bf Fix deadlocks in chan_sip in REFER and BYE handling
This resolves several deadlocks in chan_sip relating to usage of
ast_channel_bridge_peer and improves accessibility of lock debugging
function calls.

Review: https://reviewboard.asterisk.org/r/2756/
(closes issue ASTERISK-22215)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396723 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-08-15 12:12:26 +00:00
Matthew Jordan 2a8219b64a Prevent spurious memory error when appending backtrace with MALLOC_DEBUG
Backtraces are allocated outside of the usual memory tracking performed by
MALLOC_DEBUG. This allows them to be used by the memory tracking enabled
by that build option; however, it also means that when backtraces are
disposed of they have to be done so outside of the re-defined free.

This patch undef's free prior to disposing of the allocated backtrace when
a backtrace is appended as a result of 'core show locks'.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396391 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-08-08 13:54:46 +00:00
Richard Mudgett e26d4ec83a Reinclude sys/stat.h in chan_dahdi.c and remove redundant include in utils.c
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@395182 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-23 18:41:18 +00:00
David M. Lee 04cde027d4 Fix utils directory breakage.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393675 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-04 13:06:15 +00:00
David M. Lee a75fd32212 ARI - channel recording support
This patch is the first step in adding recording support to the
Asterisk REST Interface.

Recordings are stored in /var/spool/recording. Since recordings may be
destructive (overwriting existing files), the API rejects attempts to
escape the recording directory (avoiding issues if someone attempts to
record to ../../lib/sounds/greeting, for example).

(closes issue ASTERISK-21594)
(closes issue ASTERISK-21581)
Review: https://reviewboard.asterisk.org/r/2612/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393550 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 17:58:45 +00:00
David M. Lee 9ba976b19c ARI authentication.
This patch adds authentication support to ARI.

Two authentication methods are supported. The first is HTTP Basic
authentication, as specified in RFC 2617[1]. The second is by simply
passing the username and password as an ?api_key query parameter
(which allows swagger-ui[2] to authenticate more easily).

ARI usernames and passwords are configured in the ari.conf file
(formerly known as stasis_http.conf). The user may be set to
`read_only`, which will prohibit the user from issuing POST, DELETE,
etc. Also, the user's password may be specified in either plaintext,
or encrypted using the crypt() function.

Several other notes about the patch.

 * A few command line commands for seeing ARI config and status were
   also added.
 * The configuration parsing grew big enough that I extracted it to
   its own file.

 [1]: http://www.ietf.org/rfc/rfc2617.txt [2]:
 https://github.com/wordnik/swagger-ui

(closes issue ASTERISK-21277)
Review: https://reviewboard.asterisk.org/r/2649/



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393530 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:33:13 +00:00
Matthew Jordan 6258bbe7bd Update Asterisk's CDRs for the new bridging framework
This patch is the initial push to update Asterisk's CDR engine for the new
bridging framework. This patch guts the existing CDR engine and builds the new
on top of messages coming across Stasis. As changes in channel state and bridge
state are detected, CDRs are built and dispatched accordingly. This
fundamentally changes CDRs in a few ways.
(1) CDRs are now *very* reflective of the actual state of channels and bridges.
    This means CDRs track well with what an actual channel is doing - which
    is useful in transfer scenarios (which were previously difficult to pin
    down). It does, however, mean that CDRs cannot be 'fooled'. Previous
    behavior in Asterisk allowed for CDR applications, channels, and other
    properties to be spoofed in parts of the code - this no longer works.
(2) CDRs have defined behavior in multi-party scenarios. This behavior will not
    be what everyone wants, but it is a defined behavior and as such, it is
    predictable.
(3) The CDR manipulation functions and applications have been overhauled. Major
    changes have been made to ResetCDR and ForkCDR in particular. Many of the
    options for these two applications no longer made any sense with the new
    framework and the (slightly) more immutable nature of CDRs.

There are a plethora of other changes. For a full description of CDR behavior,
see the CDR specification on the Asterisk wiki.

(closes issue ASTERISK-21196)

Review: https://reviewboard.asterisk.org/r/2486/



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391947 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-06-17 03:00:38 +00:00
Alec L Davis 0b87695460 Add Asterisk Version to core show locks
Assist with reporting 'core show locks' when submitting bug reports.

Example below:

===========================
== SVN-branch-1.8-...
== Currently Held Locks
===========================


(closes issue ASTERISK-21743)

Reported by: alecdavis
Tested by: alecdavis
alecdavis (license 585)
........

Merged revisions 387294 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 387295 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387296 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-02 06:47:16 +00:00
David M. Lee aecd2429bd Fix XML encoding of 'identity display' in NOTIFY messages.
XML encoding in chan_sip is accomplished by naively building the XML
directly from strings. While this usually works, it fails to take into
account escaping the reserved characters in XML.

This patch adds an 'ast_xml_escape' function, which works similarly to
'ast_uri_encode'. This is used to properly escape the local_display
attribute in XML formatted NOTIFY messages.

Several things to note:
 * The Right Thing(TM) to do would probably be to replace the
   ast_build_string stuff with building an ast_xml_doc. That's a much
   bigger change, and out of scope for the original ticket, so I
   refrained myself.
 * It is with great sadness that I wrote my own ast_xml_escape
   function. There's one in libxml2, but it's knee-deep in
   libxml2-ness, and not easily used to one-off escape a
   string.
 * I only escaped the string we know is causing problems
   (local_display). At least some of the other strings are
   URI-encoded, which should be XML safe. Rather than figuring out
   what's safe and escaping what's not, it would be much cleaner to
   simply build an ast_xml_doc for the messages and let the XML
   library do the XML escaping. Like I said, that's out of scope.

(closes issue ABE-2902)
Reported by: Guenther Kelleter
Tested by: Guenther Kelleter
Review: http://reviewboard.digium.internal/r/365/

........

Merged revision 378919 from https://origsvn.digium.com/svn/asterisk/be/branches/C.3-bier
........

Merged revisions 378933 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 378934 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@378935 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-12 06:43:37 +00:00
Russell Bryant fad2637297 Remove compile time check HAVE_DEV_URANDOM.
The code was doing a runtime check, anyway.  The compile time check isn't
always valid (cross-compiling, packages).

Review: https://reviewboard.asterisk.org/r/2245/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@377977 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-13 16:18:52 +00:00
David M. Lee 23c53c18c0 Fixed ast_random's comment about locking.
The original comment was separated from the code at some point, and didn't
reflect the use of libc's other than glibc for Linux.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@376821 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-29 17:16:50 +00:00
Matthew Jordan 530ce21b5d Reorder startup sequence to prevent lockups when process is sent to background
Although it is very rare and timing dependent, the potential exists for the
call to 'daemon' to cause what appears to be a deadlock in Asterisk during
startup.  This can occur when a recursive mutex is obtained prior to the
daemon call executing.  Since daemon uses fork to send the process into the
background, any threading primitives are unsafe to re-use after the call.
Implementations of pthread recursive mutexes are highly likely to store the
thread identifier of the thread that previously obtained the mutex.  If
the mutex was locked prior to the fork, a subsequent unlock operation will
potentially fail as the thread identifier is no longer valid.  Since the
mutex is still locked, all subsequent attempts to grab the mutex by other
threads will block.

This behavior exhibited itself most often when DEBUG_THREADS was enabled, as
this compile time option surrounds the mutexes in Asterisk with another
recursive mutex that protects the storage of thread related information.  This
made it much more likely that a recursive mutex would be obtained prior to
daemon and unlocked after the call.

This patch does the following:
a) It backports a patch from Asterisk 11 that prevents the spawning of the
   localtime monitoring thread.  This thread is now spawned after Asterisk has
   fully booted.
b) It re-orders the startup sequence to call daemon earlier during Asterisk
   startup.  This limits the potential of threading primitives being accessed
   by initialization calls before daemon is called.
c) It removes calls to ast_verbose/ast_log/etc. prior to daemon being called.
   Developers should send error messages directly to stderr prior to daemon,
   as calls to ast_log may access recursive mutexes that store thread related
   information.
d) It reorganizes when thread local storage is created for storing lock
   information during the creation of threads.  Prior to this patch, the
   read/write lock protecting the list of threads in ast_register_thread would
   utilize the lock in the thread local storage prior to it being initialized;
   this patch prevents that.

On a very related note, this patch will *greatly* improve the stability of the
Asterisk Test Suite.

Review: https://reviewboard.asterisk.org/r/2197

(closes issue ASTERISK-19463)
Reported by: mjordan
Tested by: mjordan
........

Merged revisions 376428 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 376431 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 376441 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@376447 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-18 20:27:45 +00:00
Richard Mudgett 3a9640b605 Add MALLOC_DEBUG enhancements.
* Makes malloc() behave like calloc().  It will return a memory block
filled with 0x55.  A nonzero value.

* Makes free() fill the released memory block and boundary fence's with
0xdeaddead.  Any pointer use after free is going to have a pointer
pointing to 0xdeaddead.  The 0xdeaddead pointer is usually an invalid
memory address so a crash is expected.

* Puts the freed memory block into a circular array so it is not reused
immediately.

* When the circular array rotates out a memory block to the heap it checks
that the memory has not been altered from 0xdeaddead.

* Made the astmm_log message wording better.

* Made crash if the DO_CRASH menuselect option is enabled and something is
found.

* Fixed a potential alignment issue on 64 bit systems.
struct ast_region.data[] should now be aligned correctly for all
platforms.

* Extracted region_check_fences() from __ast_free_region() and
handle_memory_show().

* Updated handle_memory_show() CLI usage help.

Review: https://reviewboard.asterisk.org/r/2182/
........

Merged revisions 376029 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 376030 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 376048 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@376049 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-08 17:38:31 +00:00
Mark Michelson f2bb9afe17 Multiple revisions 375993-375994
........
  r375993 | mmichelson | 2012-11-07 11:01:13 -0600 (Wed, 07 Nov 2012) | 30 lines
  
  Fix misuses of timeouts throughout the code.
  
  Prior to this change, a common method for determining if a timeout
  was reached was to call a function such as ast_waitfor_n() and inspect
  the out parameter that told how many milliseconds were left, then use
  that as the input to ast_waitfor_n() on the next go-around.
  
  The problem with this is that in some cases, submillisecond timeouts
  can occur, resulting in the out parameter not decreasing any. When this
  happens thousands of times, the result is that the timeout takes much
  longer than intended to be reached. As an example, I had a situation where
  a 3 second timeout took multiple days to finally end since most wakeups
  from ast_waitfor_n() were under a millisecond.
  
  This patch seeks to fix this pattern throughout the code. Now we log the
  time when an operation began and find the difference in wall clock time
  between now and when the event started. This means that sub-millisecond timeouts
  now cannot play havoc when trying to determine if something has timed out.
  
  Part of this fix also includes changing the function ast_waitfor() so that it
  is possible for it to return less than zero when a negative timeout is given
  to it. This makes it actually possible to detect errors in ast_waitfor() when
  there is no timeout.
  
  (closes issue ASTERISK-20414)
  reported by David M. Lee
  
  Review: https://reviewboard.asterisk.org/r/2135/
........
  r375994 | mmichelson | 2012-11-07 11:08:44 -0600 (Wed, 07 Nov 2012) | 3 lines
  
  Remove some debugging that accidentally made it in the last commit.
........

Merged revisions 375993-375994 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 375995 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 376014 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@376015 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-07 19:15:26 +00:00
Kinsey Moore e13db61695 Implement workaround for BETTER_BACKTRACES crash
When compiling with BETTER_BACKTRACES enabled, Asterisk will sometimes
crash when "core show locks" is run. This happens regularly in the
testsuite since several tests run "core show locks" to help with
debugging. This seems to be a fault with libraries on certain operating
systems (notably CentOS 6.2/6.3) running on virtual machines and
utilizing gcc 4.4.6.

(closes issue ASTERISK-20090)
........

Merged revisions 371690 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 371691 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 371692 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@371693 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-08-27 14:13:44 +00:00
Mark Michelson 6a539ace84 Fix misuses of asprintf throughout the code.
This fixes three main issues

* Change asprintf() uses to ast_asprintf() so that it
pairs properly with ast_free() and no longer causes
MALLOC_DEBUG to freak out.

* When ast_asprintf() fails, set the pointer NULL if
it will be referenced later.

* Fix some memory leaks that were spotted while taking
care of the first two points.

(Closes issue ASTERISK-20135)
reported by Richard Mudgett

Review: https://reviewboard.asterisk.org/r/2071
........

Merged revisions 371590 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 371591 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 371592 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@371593 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-08-21 21:01:11 +00:00
Kinsey Moore 6c8f4f5fff Fix for commit r371535
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@371536 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-08-20 15:01:08 +00:00
Kinsey Moore ca314fe1e2 Apply work-around for BETTER_BACKTRACES crash
When compiling with BETTER_BACKTRACES enabled, Asterisk will sometimes
crash when "core show locks" is run. This happens regularly in the
testsuite since several tests run "core show locks" to help with
debugging. This seems to be a fault with libraries on certain operating
systems (notably CentOS 6.2/6.3) running on virtual machines and
utilizing gcc 4.4.6.

(issue ASTERISK-20090)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@371535 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-08-20 14:45:07 +00:00
Kinsey Moore 9b16c8b0f6 Clean up and ensure proper usage of alloca()
This replaces all calls to alloca() with ast_alloca() which calls gcc's
__builtin_alloca() to avoid BSD semantics and removes all NULL checks
on memory allocated via ast_alloca() and ast_strdupa().

(closes issue ASTERISK-20125)
Review: https://reviewboard.asterisk.org/r/2032/
Patch-by: Walter Doekes (wdoekes)
........

Merged revisions 370642 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 370643 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370655 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-07-31 20:21:43 +00:00
Kevin P. Fleming 166b4e2b30 Multiple revisions 369001-369002
........
  r369001 | kpfleming | 2012-06-15 10:56:08 -0500 (Fri, 15 Jun 2012) | 11 lines
  
  Add support-level indications to many more source files.
  
  Since we now have tools that scan through the source tree looking for files
  with specific support levels, we need to ensure that every file that is
  a component of a 'core' or 'extended' module (or the main Asterisk binary)
  is explicitly marked with its support level. This patch adds support-level
  indications to many more source files in tree, but avoids adding them to
  third-party libraries that are included in the tree and to source files
  that don't end up involved in Asterisk itself.
........
  r369002 | kpfleming | 2012-06-15 10:57:14 -0500 (Fri, 15 Jun 2012) | 3 lines
  
  Add a script to enable finding source files without support-levels defined.
........

Merged revisions 369001-369002 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 369005 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@369013 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-06-15 16:20:16 +00:00
Richard Mudgett 745484e1b3 Fix error paths in action_hangup() for AMI Hangup action.
* Check allocation function return values for failure.  Crashing is bad.

* Tweak ast_regex_string_to_regex_pattern() parameters for proper ast_str 
usage.  


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@368714 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-06-08 21:08:17 +00:00
Joshua Colp 380c7c5c39 Add res_http_websocket module which implements the WebSocket protocol according to RFC 6455.
Review: https://reviewboard.asterisk.org/r/1952/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@368359 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-06-02 21:13:36 +00:00
Mark Murawki e4252eac10 Allow the Hangup manager action to match channels by regex
* Hangup now can take a regular expression as the Channel option.  If you want
  to hangup multiple channels, use /regex/ as the Channel option.  Existing
  behavior to hanging up a single channel is unchanged, but if you pass a regex,
  the manager will send you a list of channels back that were hung up.

(closes issue ASTERISK-19575)
Reported by: Mark Murawski
Tested by: Mark Murawski



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@361038 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-04-03 19:31:25 +00:00
Jonathan Rose c6979ff581 Adds F option to Bridge application
Similar to dial and queue F option.

(Closes issue ASTERISK-19282)
Reported by: To
Patches:
	bridge_f-v3.diff uploaded by To (license 6347)
Review: https://reviewboard.asterisk.org/r/1825/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@360227 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-03-22 21:25:22 +00:00
Kinsey Moore c5b3db1956 Kill off red blobs in most of main/*
Everything still compiled after making these changes, so I assume these
whitespace-only changes didn't break anything (and shouldn't have).


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@360190 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-03-22 19:51:16 +00:00
Matthew Jordan cca1f9f48a Fix remotely exploitable stack overflow in HTTP manager
There exists a remotely exploitable stack buffer overflow in HTTP digest
authentication handling in Asterisk.  The particular method in question
is only utilized by HTTP AMI.  When parsing the digest information, the
length of the string is not checked when it is copied into temporary buffers
allocated on the stack.

This patch fixes this behavior by parsing out pre-defined key/value pairs
and avoiding unnecessary copies to the stack.

(closes issue ASTERISK-19542)
Reported by: Russell Bryant
Tested by: Matt Jordan
........

Merged revisions 359706 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 359707 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@359708 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-03-15 19:11:03 +00:00
Walter Doekes 41f5a1ab35 Update stringfield documentation for removed second va_list in favor of va_copy.
In r320946, the second va_list that was passed to ast_string_field_build_va
and friends, was removed. This patch updates the documentation to reflect that.
........

Merged revisions 357620 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@357621 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-02-29 20:41:38 +00:00
Walter Doekes 735e48f92f Use __alignof__ instead of sizeof for stringfield length storage.
Kevin P Fleming suggested that r343157 should use __alignof__ instead
of sizeof. For most systems this won't be an issue, but better fix it
now while it's still fresh.

Review: https://reviewboard.asterisk.org/r/1573
........

Merged revisions 344843 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 344845 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@344846 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-11-11 22:00:14 +00:00
Walter Doekes 7fd2a68b0e Ensure that string field lengths are properly aligned
Integers should always be aligned. For some platforms (ARM, SPARC) this
is more important than for others. This changeset ensures that the
string field string lengths are aligned on *all* platforms, not just on
the SPARC for which there was a workaround. It also fixes that the
length integer can be resized to 32 bits without problems if needed.

(closes issue ASTERISK-17310)
Reported by: radael, S Adrian
Reviewed by: Tzafrir Cohen, Terry Wilson
Tested by: S Adrian

Review: https://reviewboard.asterisk.org/r/1549
........

Merged revisions 343157 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 343158 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@343163 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-11-02 22:02:07 +00:00
Terry Wilson fc8d4e823c Use va_copy for stringfields
The ast_string_field_build_va functions were written to take to separate
va_lists to work around FreeBSD 4 not having va_copy defined.

In the end, we don't support anything using gcc < 3 anyway because we use
va_copy all over the place anyway. This patch just simplifies things by
removing the second va_list function arguments in favor of va_copy.

Review: https://reviewboard.asterisk.org/r/1233/
--This line, and those below, will be ignored--

M    include/asterisk/stringfields.h
M    main/utils.c
M    main/channel.c


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@320946 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-05-26 15:55:22 +00:00
Sean Bright fe5938c51e Merged revisions 316917-316919 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

........
  r316917 | seanbright | 2011-05-04 22:23:28 -0400 (Wed, 04 May 2011) | 5 lines
  
  Make sure that tcptls_session is properly initialized.
  
  (issue #18598)
  Reported by: ksn
........
  r316918 | seanbright | 2011-05-04 22:25:20 -0400 (Wed, 04 May 2011) | 5 lines
  
  Look at the correct buffer for our digest info instead of an empty one.
  
  (issue #18598)
  Reported by: ksn
........
  r316919 | seanbright | 2011-05-04 22:30:45 -0400 (Wed, 04 May 2011) | 10 lines
  
  Use the correct HTTP method when generating our digest, otherwise we always fail.
  
  When calculating the 'A2' portion of our digest for verification, we need the
  HTTP method that is currently in use.  Unfortunately our mapping function was
  incorrect, resulting in invalid hashes being generated and, in turn, failures
  in authentication.
  
  (closes issue #18598)
  Reported by: ksn
........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@316920 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-05-05 02:34:29 +00:00
Alec L Davis 858c11f075 Merged revisions 310781 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

........
  r310781 | alecdavis | 2011-03-15 14:00:55 +1300 (Tue, 15 Mar 2011) | 10 lines
  
  core show locks: display ThreadID in hexadecimal
  
  Allow easier cross referencing of thread ID's with GDB backtraces
  
  (closes issue #18968)
  Reported by: alecdavis
  Patches: 
        bug18968.diff.txt uploaded by alecdavis (license 585)
........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@310833 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-03-15 01:36:26 +00:00
Tilghman Lesher 16c3ea3d42 Merged revisions 304950 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

........
  r304950 | tilghman | 2011-01-31 00:41:36 -0600 (Mon, 31 Jan 2011) | 18 lines
  
  Change mutex tracking so that it only consumes memory in the core mutex object when it's actually being used.
  
  This reduces the overall size of a mutex which was 3016 bytes before this back
  down to 216 bytes (this is on 64-bit Linux with a glibc-implemented mutex).
  The exactness of the numbers here may vary slightly based upon how mutexes are
  implemented on a platform, but the long and short of it is that prior to this
  commit, chan_iax2 held down 98MB of memory on a 64-bit system for nothing more
  than a table of 32767 locks.  After this commit, the same table occupies a mere
  7MB of memory.
  
  (closes issue #18194)
   Reported by: job
   Patches: 
         20110124__issue18194.diff.txt uploaded by tilghman (license 14)
   Tested by: tilghman
   
  Review: https://reviewboard.asterisk.org/r/1066
........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@304951 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-31 06:50:49 +00:00
Matthew Nicholson 2686253f16 Use unsigned char in comparison for UTF8 check to quiet a compiler warning.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@303638 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-25 15:52:42 +00:00
Matthew Nicholson e706b5706e According to section 19.1.2 of RFC 3261:
For each component, the set of valid BNF expansions defines exactly
  which characters may appear unescaped.  All other characters MUST be
  escaped.

This patch modifies ast_uri_encode() to encode strings in line with this recommendation.  This patch also adds an ast_escape_quoted() function which escapes '"' and '\' characters in quoted strings in accordance with section 25.1 of RFC 3261.  The ast_uri_encode() function has also been modified to take an ast_flags struct describing the set of rules it should use when escaping characters to allow for it to escape SIP URIs in addition to HTTP URIs and other types of URIs or variations of those two URI types in the future.

The ast_uri_decode() function has also been modified to accept an ast_flags struct describing the set of rules to use when decoding to enable decoding '+' as ' ' in legacy http URLs.

The unit tests for these functions have also been updated.

ABE-2705

Review: https://reviewboard.asterisk.org/r/1081/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@303509 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-24 18:59:22 +00:00
Sean Bright 5943a34463 Merged revisions 302555 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
  r302555 | seanbright | 2011-01-19 14:03:32 -0500 (Wed, 19 Jan 2011) | 14 lines
  
  Merged revisions 302554 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.6.2
  
  ........
    r302554 | seanbright | 2011-01-19 14:02:29 -0500 (Wed, 19 Jan 2011) | 7 lines
    
    Don't call strlen() when we only need to look at the next character or two.
    
    (closes issue #18042)
    Reported by: wdoekes
    Patches:
          astsvn-inefficient-ast-uri-decode.patch uploaded by wdoekes (license 717)
  ........
................


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@302556 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-19 19:04:25 +00:00
Sean Bright bd26287e88 Merged revisions 302505 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
  r302505 | seanbright | 2011-01-19 12:58:11 -0500 (Wed, 19 Jan 2011) | 14 lines
  
  Merged revisions 302504 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.6.2
  
  ........
    r302504 | seanbright | 2011-01-19 12:56:32 -0500 (Wed, 19 Jan 2011) | 7 lines
    
    Make sure that h_length is set when we short-circuit out of ast_gethostbyname.
    
    (closes issue #16135)
    Reported by: thedavidfactor
    Patches:
          utils.patch uploaded by thedavidfactor (license 903)
  ........
................


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@302507 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-19 17:59:18 +00:00
Matthew Nicholson 50a0c8a646 Merged revisions 301308 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
  r301308 | mnicholson | 2011-01-11 12:51:40 -0600 (Tue, 11 Jan 2011) | 18 lines
  
  Merged revisions 301307 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.6.2
  
  ................
    r301307 | mnicholson | 2011-01-11 12:42:05 -0600 (Tue, 11 Jan 2011) | 11 lines
    
    Merged revisions 301305 via svnmerge from 
    https://origsvn.digium.com/svn/asterisk/branches/1.4
    
    ........
      r301305 | mnicholson | 2011-01-11 12:34:40 -0600 (Tue, 11 Jan 2011) | 4 lines
      
      Prevent buffer overflows in ast_uri_encode()
      
      ABE-2705
    ........
  ................
................


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@301309 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-01-11 18:55:16 +00:00
Tilghman Lesher b98e47d119 Merged revisions 298960 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
  r298960 | tilghman | 2010-12-17 17:52:04 -0600 (Fri, 17 Dec 2010) | 20 lines
  
  Merged revisions 298957 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.6.2
  
  ................
    r298957 | tilghman | 2010-12-17 17:30:55 -0600 (Fri, 17 Dec 2010) | 13 lines
    
    Merged revisions 298905 via svnmerge from 
    https://origsvn.digium.com/svn/asterisk/branches/1.4
    
    ........
      r298905 | tilghman | 2010-12-17 15:40:56 -0600 (Fri, 17 Dec 2010) | 6 lines
      
      Let Asterisk find better backtrace information with libbfd.
      
      The menuselect option BETTER_BACKTRACES, if enabled, will use libbfd to search
      for better symbol information within both the Asterisk binary, as well as
      loaded modules, to assist when using inline backtraces to track down problems.

      Review: https://reviewboard.asterisk.org/r/1055/
    ........
  ................
................


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@298961 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-12-18 00:08:13 +00:00
Jeff Peeler 78bd0de1a9 Add support for several platforms to obtain the real thread ID.
Already had the pthread ID which is not the same.  The most obvious enhancement
is in the "core show threads" output. As stated in the utils header, if the
platform isn't supported -1 is reported (instead of the process ID previously).


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@298137 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-12-12 03:58:33 +00:00
Tilghman Lesher fc21c6f9e9 Merged revisions 281085 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

........
  r281085 | tilghman | 2010-08-06 13:57:10 -0500 (Fri, 06 Aug 2010) | 8 lines
  
  Fix alignment of stringfields on the SPARC architecture
  
  (closes issue #17789)
   Reported by: Ian Mason
   Patches: 
         20100806__issue17789__2.diff.txt uploaded by tilghman (license 14)
   Tested by: Ian_Mason
........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@281086 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-08-06 18:58:39 +00:00
Tzafrir Cohen c613897d1c Fix various typos reported by Lintian
(Also fix the typos in the comments)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@273641 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-07-02 15:57:02 +00:00
Jeff Peeler 2d26a2da1f Add new unit test for stringfields.
(Copied from reviewboard)
Tests the following:
1. Basic allocation and setting of string fields.
2. Shrinking a string field and re-expanding it.
3. Growing the last allocation in a string field pool.
4. Setting a string to a large value such that a new string field pool must be
allocated.
In each part, we make sure that the string field is accurate (has the correct
value in it), make sure that the 2 bytes before the string field has the correct
capacity for the field, and for tests 2-4, we make sure that the string field is
where we expect it to be in memory.

Also tested:
5. Shrinking a string field and partially re-expanding it.
6. Setting strings in such a way as to create three separate string field pools
and then removing the middle pool.

There is a bug fix in the init function, which ensures the embedded_pool is set
to NULL which is important for stack allocated structures.

Review: https://reviewboard.asterisk.org/r/185/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@251736 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-03-10 23:15:55 +00:00
David Vossel d16b89be17 RFC compliant uri and display-name encode/decode
1.  URI Encoding
This patch changes ast_uri_encode()'s behavior when doreserved is enabled.
Previously when doreserved was enabled only a small set of reserved
characters were encoded.  This set was comprised primarily of the reserved
characters defined in RFC3261 section 25.1, but contained other characters as
well.  Rather than only escaping the reserved set, doreserved now escapes
all characters not within the unreserved set as defined by RFC 3261 and
RFC 2396.  Also, the 'doreserved' variable has been renamed to 'do_special_char'
in attempts to avoid confusion.

When doreserve is not enabled, the previous logic of only encoding the
characters <= 0X1F and > 0X7f remains, except for the '%' character, which
must always be encoded as it signifies a HEX escaped character during the decode
process.

2. URI Decoding: Break up URI before decode.
In chan_sip.c ast_uri_decode is called on the entire URI instead of it's
individual parts after it is parsed.  This is not good as ast_uri_decode
can introduce special characters back into the URI which can mess up parsing.
This patch resolves this by not decoding a URI until parsing is completely
done.  There are many instances where we check to see if pedantic checking
is enabled before we decode a URI.  In these cases a new macro,
SIP_PEDANTIC_DECODE, is used on the individual parsed segments of the URI
rather than constantly putting if (pedantic) { decode() } checks everywhere
in the code.  In the areas where ast_uri_decode is not dependent upon
pedantic checking this macro is not used, but decoding is still moved to
each individual part of the URI.  The only behavior that should change from
this patch is the time at which decoding occurs.

Since I had to look over every place URI parsing occurs to create this
patch, I found several places where we use duplicate code for parsing.
To consolidate the code, those areas have updated to use the parse_uri()
function where possible.

3. SIP display-name decoding according to RFC3261 section 25.
To properly decode the display-name portion of a FROM header, chan_sip's
get_calleridname() function required a complete re-write.  More information
about this change can be found in the comments at the beginning of this function.

4. Unit Tests.
Unit tests for ast_uri_encode, ast_uri_decode, and get_calleridname() have been
written.  This involved the addition of the test_utils.c file for testing the
utils api.

(closes issue #16299)
Reported by: wdoekes
Patches:
      astsvn-16299-get_calleridname.diff uploaded by wdoekes (license 717)
      get_calleridname_rewrite.diff uploaded by dvossel (license 671)
Tested by: wdoekes, dvossel, Nick_Lewis

Review: https://reviewboard.asterisk.org/r/469/



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@243200 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-01-26 16:30:08 +00:00