Summary:ASTERISK-25612: Configuration parser handles unsigned integers as signed integers
Reporter:Gianluca Merlo (gian)Labels:
Date Opened:2015-12-05 15:25:21.000-0600Date Closed:2016-09-23 14:21:19
Versions:13.6.0 Frequency of

I seem to have stumbled in what seems to be a bug in Asterisk's configuration parser, more specifically it seems that if an option is registered with the unsigned integer type, it is nonetheless handled as if the value should be a signed integer.

To help you reproduce this issue, I can consistently experience it while trying to configure {{res_hep.so}} via its configuration file {{hep.conf}}. One of {{hep.conf}} options is {{capture_id}} which is intended to be an unsigned integer. {{res/res_hep.c}} registers the option on load with

aco_option_register(&cfg_info, "capture_id", ACO_EXACT, global_options, "0", OPT_UINT_T, 0, STRFLDSET(struct hepv3_global_config, capture_id));

however, if I configure

capture_id = 2147483648

the module fails to load and I get (logs):

[Dec  5 21:59:16] DEBUG[5547] config.c: extract int from [0] in [-2147483648, 2147483647] gives [0](0)
[Dec  5 21:59:16] DEBUG[5547] config.c: Parsing /etc/asterisk/hep.conf
[Dec  5 21:59:16] DEBUG[5547] config.c: extract int from [2147483648] in [-2147483648, 2147483647] gives [0](1)
[Dec  5 21:59:16] ERROR[5547] config_options.c: Error parsing capture_id=2147483648 at line 31 of
[Dec  5 21:59:16] ERROR[5547] config_options.c: In hep.conf: Processing options for general failed

Regarding the source, and the fix for it, it seems to me that the bug is in the code of {{main/config_options.c}}, in the implementation of {{uint_handler_fn()}}. This functions initializes parser flags as

unsigned int flags = PARSE_INT32 | opt->flags;

while it should initialize them as

unsigned int flags = PARSE_UINT32 | opt->flags;

I hope my guess is right, and you can confirm and fix it in the next release. Thank you for your assistance.
Comments:By: Asterisk Team (asteriskteam) 2015-12-05 15:25:22.850-0600

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].