Summary:ASTERISK-24514: res_pjsip_outbound_registration: stack overflow when using non-default sorcery wizard
Reporter:Kevin Harwell (kharwell)Labels:
Date Opened:2014-11-10 17:16:26.000-0600Date Closed:2014-12-09 12:37:59.000-0600
Versions:Frequency of
is duplicated byASTERISK-23807 PJSip dynamic realtime registrations - ps_registrations shouldn't exist
Description:When using a non-default sorcery wizard (in this instance realtime) for outbound registrations and after adding in an appropriate call to  {{ast_sorcery_apply_config()}} (since it is missing) Asterisk will crash after a stack overflow occurs due to the code infinitely recursing.

The backtrace generated is quite large, so below is the relevant repeating lines:

#17 0x07174de9 in sip_outbound_registration_apply (sorcery=0x86f19fc, obj=0xc9c6454) at res_pjsip_outbound_registration.c:804
#18 0x081fc6b8 in ast_sorcery_objectset_apply (sorcery=0x86f19fc, object=0xc9c6454, objectset=0xc9c6ce8) at sorcery.c:1273
#19 0x00b7834b in sorcery_realtime_retrieve_fields (sorcery=0x86f19fc, data=0x8828628, type=0x881c914 "registration", fields=0xc9c63e0) at res_sorcery_realtime.c:161
#20 0x00b783b9 in sorcery_realtime_retrieve_id (sorcery=0x86f19fc, data=0x8828628, type=0x881c914 "registration", id=0xc9c4b40 "117") at res_sorcery_realtime.c:172
#21 0x081fbf74 in ast_sorcery_retrieve_by_id (sorcery=0x86f19fc, type=0x7177672 "registration", id=<value optimized out>) at sorcery.c:1476
#22 0x07174de9 in sip_outbound_registration_apply (sorcery=0x86f19fc, obj=0xc9c4f0c) at res_pjsip_outbound_registration.c:804

The issue stems from the fact that res_sorcery_realtime, unlike res_sorcery_config, calls {{ast_sorcery_objectset_apply()}} when retrieving a field by ID or when retrieving multiple fields.{{sip_outbound_registration_apply()}} calls {{ast_sorcery_object_get_by_id()}} to try to determine if there is already an existing configured object it can reuse. This kicks off the infinite recursion.