[OpenSIPS-Devel] [OpenSIPS/opensips] 8d139f: usrloc API: Make get_urecord() more robust

Liviu Chircu liviu at opensips.org
Wed Jan 17 04:53:25 EST 2018


  Branch: refs/heads/2.3
  Home:   https://github.com/OpenSIPS/opensips
  Commit: 8d139f3756014b14b2f604cc24371044456f92ce
      https://github.com/OpenSIPS/opensips/commit/8d139f3756014b14b2f604cc24371044456f92ce
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/usrloc/udomain.c

  Log Message:
  -----------
  usrloc API: Make get_urecord() more robust

Zeroize the output pointer if record is not found.

(cherry picked from commit d4967201bf4243646eef0a92be1c37dff0aba29d)


  Commit: 99432b1a9af7874263884371a1c02caa694597d9
      https://github.com/OpenSIPS/opensips/commit/99432b1a9af7874263884371a1c02caa694597d9
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/usrloc/dlist.c

  Log Message:
  -----------
  usrloc: Fix locking for contact_id-based deletion

The delete_ucontact_from_id(), get_ucontact_from_id() pair of functions
were masking possible code execution paths which would lead to unsafe memory
access. This, in turn, would cause the ping_checker_timer() job of nathelper to
occasionally crash and burn.

Reported by solo at astercc.org.

(cherry picked from commit 18a93c89aa1c32498689a6f6dd09911272c18896)


  Commit: 520b4d4d3ad07a6b99009b77d880f7c6a3a7c79d
      https://github.com/OpenSIPS/opensips/commit/520b4d4d3ad07a6b99009b77d880f7c6a3a7c79d
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M ut.h

  Log Message:
  -----------
  Fix int2str() function signature

Although implemented to be able to print 64-bit integers, int2str()
downcasted all of its parameters to an "unsigned long" type, thus
breaking behavior on 32-bit architectures.

(cherry picked from commit a5d633924fc78cd4d9999a727ab529cb1bf50405)


  Commit: 3894087d52a991e9e7b5228beb559f89824fcd65
      https://github.com/OpenSIPS/opensips/commit/3894087d52a991e9e7b5228beb559f89824fcd65
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M ut.h

  Log Message:
  -----------
  Add str2int64() parsing function

(cherry picked from commit e9be01680557a030c5fd6346299f5db663467018)


  Commit: f47d185e0148432dbe639c382cefee9427b5d76b
      https://github.com/OpenSIPS/opensips/commit/f47d185e0148432dbe639c382cefee9427b5d76b
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/usrloc/udomain.h
    M modules/usrloc/urecord.c
    M modules/usrloc/urecord.h
    M modules/usrloc/usrloc.c
    M modules/usrloc/usrloc.h

  Log Message:
  -----------
  usrloc: Add some useful API functions

    * get_ucontact_from_id() - fetch both ct and rec from an id
    * next_contact_id() - fetch and advance the current ct counter

(cherry picked from commit 15a5067b2d493c273842b723199d42c695a1b93f)


  Commit: b2554c3c3a75f0ce8ef67c932e9dfd978eeff524
      https://github.com/OpenSIPS/opensips/commit/b2554c3c3a75f0ce8ef67c932e9dfd978eeff524
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/usrloc/urecord.c

  Log Message:
  -----------
  usrloc: Allow forced IDs during contact inserts

(cherry picked from commit 7d4894943ad522406d1f2cb9231821c91f423562)


  Commit: 3a079a756aafbf1cf306ff99d7cb8b9ad8d11f14
      https://github.com/OpenSIPS/opensips/commit/3a079a756aafbf1cf306ff99d7cb8b9ad8d11f14
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/usrloc/udomain.c
    M modules/usrloc/urecord.c
    M modules/usrloc/urecord.h

  Log Message:
  -----------
  usrloc: Add urecord reference counting mechanism

This mechanism is required by the mid-registrar, which needs to
"reserve" contact IDs while the main registrar decides upon them.
This means that a blank urecord structure must be kept alive during
this process.

By reference counting the blank urecord structures, we prevent them
from being cleared by the timer before the outgoing registrations
get a chance to receive a reply.

(cherry picked from commit ad274fad9a6fd072737d45230a0c297d0e4b9329)


  Commit: 512acb13b284a542c909bbeab25d7497587418f1
      https://github.com/OpenSIPS/opensips/commit/512acb13b284a542c909bbeab25d7497587418f1
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Fix possible crash in mirror mode

(cherry picked from commit 8c46ab3cad07029a1e78fdb1d57300247c00c4eb)


  Commit: 1c0ea020746d1f010b7d224b216d97ce6cab6cf6
      https://github.com/OpenSIPS/opensips/commit/1c0ea020746d1f010b7d224b216d97ce6cab6cf6
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/lookup.c
    M modules/mid_registrar/lookup.h
    M modules/mid_registrar/mid_registrar.c
    M modules/mid_registrar/mid_registrar.h
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Fix NAT issues in "contact" insertion mode

This patch completely reworks the saving/matching logic with regards
to the SIP contacts generated by the mid-registrar. It is only relevant
to working modes "0" (mirror) and "1" (contact throttling).

The former logic (encoding the requests's Contact as a URI parameter
of the outgoing contact) was somewhat stateless, as it would forward
requests to the mid-registrar's contacts directly to their actual Contact
URIs (UA side). When NAT comes into play, this no longer works well.

Fortunately, the user location already handles this problem. Thus, we
change the mid-registrar to advertise contact IDs instead of the device's
contact. As requests arrive for the contact IDs, we are easily able to
look up their corresponding user location AoR, contact, along with any
other useful information for NAT traversal.

(cherry picked from commit 7e190a8b1cdcdfe66afe9eea4b0be4c75f275a89)


  Commit: 695e7d4309021c489b53d5c780af88d75c94963c
      https://github.com/OpenSIPS/opensips/commit/695e7d4309021c489b53d5c780af88d75c94963c
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/mid_registrar.h
    M modules/mid_registrar/save.c
    M modules/mid_registrar/ulcb.c

  Log Message:
  -----------
  mid_registrar: Fix CSeq handling for De-REGISTERs

Keep track of outgoing CSeq values and use this value during
self-generated de-registrations, rather than using the tm's built-in
default CSeq value of "13".

(cherry picked from commit 016da2f7f31b764da5dcce1d4189b8f9ef77b5cb)


  Commit: a8b63f5a7c36d3b4bf2de4a3004de07a507c7111
      https://github.com/OpenSIPS/opensips/commit/a8b63f5a7c36d3b4bf2de4a3004de07a507c7111
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/save.c
    M modules/usrloc/urecord.c

  Log Message:
  -----------
  usrloc: Fix bad comparison

Also complete commit d3790e6c

Reported by Răzvan Crainea
Fixes Coverity CID #180087
Fixes Coverity CID #180093

(cherry picked from commit 0124344f9733a123753435367525ec9f56e06f1b)


  Commit: 16bd2dd273d93dddf948cc6eb5fd5f609cbb8291
      https://github.com/OpenSIPS/opensips/commit/16bd2dd273d93dddf948cc6eb5fd5f609cbb8291
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Restore reply contact mangling

The contact rework commits have rendered the restore_reply_contacts()
function obsolete, thus the contact headers were propagating upstream unchanged.

We now rebuild the reply contact set in all modes by using build_contacts()

Thanks to Răzvan Crainea for spotting the issue

(cherry picked from commit f298587d6277d28e01ab26f64655a8b5d1bcf100)


  Commit: 478637e0e8f43f308de1395efc820d19fd65263c
      https://github.com/OpenSIPS/opensips/commit/478637e0e8f43f308de1395efc820d19fd65263c
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Fix a CSeq bug in mode == 1

Contact updates would not also update the last cseq value. This, in turn,
would lead to SIP-wise incorrect self-generated de-registrations.

(cherry picked from commit 7bcf0323369587ae0f153de1f7a87c7f85aefd4d)


  Commit: d3bcf482bb67d0b787d7ebcf4050f7eb0eca1573
      https://github.com/OpenSIPS/opensips/commit/d3bcf482bb67d0b787d7ebcf4050f7eb0eca1573
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/mid_registrar.c
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Restore "default_expires" and "max_expires"

These registrar modparams were left unmaintained / ignored during development.
However, they are still valid and completely separate from
"outgoing_expires". The former two params control ingress expirations,
while the latter one controls egress expirations.

To match the newly introduced defaults, we also increase the default
"outgoing_expires" from 600s to 3600s.

(cherry picked from commit 67c31603e2215bca6211bcaaa4b0682d9325fa18)


  Commit: 2adf24ff2fffa96cc237d332b48d5acead1cb7bb
      https://github.com/OpenSIPS/opensips/commit/2adf24ff2fffa96cc237d332b48d5acead1cb7bb
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/README
    M modules/mid_registrar/doc/mid_registrar_admin.xml

  Log Message:
  -----------
  mid_registrar: Update docs

(cherry picked from commit fee1ccb72bc62823259dedfaccd5a262c8dbd1e3)


  Commit: 59f98e968945cec3b8220c4100145d1e0a27f07b
      https://github.com/OpenSIPS/opensips/commit/59f98e968945cec3b8220c4100145d1e0a27f07b
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/lookup.c

  Log Message:
  -----------
  mid_registrar: Never parallel fork in "mode == 1"

This patch fixes a subtle bug where a "mode == 1" mid-registrar would
parallel fork to a random number of contacts by walking the remaining
"->next" values of the currently looked up contact.

(cherry picked from commit 02b114902dc91ea3a1f2dfc36d00658150cb9946)


  Commit: 370705422853538bcfef30d28f283a3b4ef7ba5a
      https://github.com/OpenSIPS/opensips/commit/370705422853538bcfef30d28f283a3b4ef7ba5a
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M lib/reg/ci.c
    M lib/reg/ci.h

  Log Message:
  -----------
  Add a "struct ucontact_info" logging function

(cherry picked from commit a2dd10a49b2557c1343cd87c364a1144e9ea7118)


  Commit: dbfc155d9cbd60a0ab72e49a9310cc3a25fdbda6
      https://github.com/OpenSIPS/opensips/commit/dbfc155d9cbd60a0ab72e49a9310cc3a25fdbda6
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/Makefile
    M modules/mid_registrar/mid_registrar.c
    M modules/mid_registrar/mid_registrar.h
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Fix a PKG memory leak

Although the TMCB_RESPONSE_IN callback provides a reference to the initial
request during reply processing, this sip_msg must not be parsed (i.e. passed
to parse_headers()), otherwise we leak PKG memory, since parsing is
PKG-based, while the request buffer is copied in SHM.

The current workaround for mid_registrar is to immediately duplicate all
contact-related data we could possibly need, should the contact successfully
register on the downstream registrar. This copying takes place during request
processing. Once the reply arrives, we only make use of this info in order to
store the contact in usrloc, and barely even use the "req" sip_msg
provided by tm.

(cherry picked from commit 86628e6d418ed72d159ebb1b055b86daca0c4f6e)


  Commit: f48a0cc906dd73ae13d07f21d0373332b48c2ce0
      https://github.com/OpenSIPS/opensips/commit/f48a0cc906dd73ae13d07f21d0373332b48c2ce0
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Fix unused variable

(cherry picked from commit 3acaf2e92a74cd8b13539eb75cf45a5edcc352ae)


  Commit: 6894b3ce3acd5fb59a054824f81a6948be4f2d86
      https://github.com/OpenSIPS/opensips/commit/6894b3ce3acd5fb59a054824f81a6948be4f2d86
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Improve the advertised socket logic

Instead of blindly advertising the first UDP interface in the
self-generated, outgoing Contact URIs, the mid_registrar is now
aware of the next SIP hop and properly advertises the actual
sending interface which will be used. This includes any forced
send socket logic at script level.

(cherry picked from commit 7bafce982b1c7a2416025fed6b04b4d9dffc5b0a)


  Commit: 66a0cd5d2cbcc0a443ade31c76838dd8f9d3248d
      https://github.com/OpenSIPS/opensips/commit/66a0cd5d2cbcc0a443ade31c76838dd8f9d3248d
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Fix unsafe strdup operation

(cherry picked from commit 14baedfbd23cd513347d46f3a4412e3e3aad1adf)


  Commit: b00e6ffbe49326ac63a85138bcb995a42d364560
      https://github.com/OpenSIPS/opensips/commit/b00e6ffbe49326ac63a85138bcb995a42d364560
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2018-01-17 (Wed, 17 Jan 2018)

  Changed paths:
    M modules/mid_registrar/save.c

  Log Message:
  -----------
  mid_registrar: Fix an AoR throttling bug

Do not apply min/max "expires" module limitations when computing the
main registrar's contact expiration value.

(cherry picked from commit 0d1bc44237b8046b7ea0fb34c9806806c913de2d)


Compare: https://github.com/OpenSIPS/opensips/compare/96452b15ad14...b00e6ffbe493


More information about the Devel mailing list