Summary:ASTERISK-09264: res_config_mysql segfaults after merging with 5881
Reporter:Sergey Tamkovich (sergee)Labels:
Date Opened:2007-04-16 04:42:46Date Closed:2007-04-16 10:39:44
Versions:Frequency of
Environment:Attachments:( 0) aa-cleanup-r365.diff
( 1) r366.diff
Description:This patch cleans res_config_mysql a little. There were a lot of submits to asterisk addons lately, and some things are broken now.

1. Old res_mysql.conf files are not compatable with new one.
2. res_config_mysql segfaults, when any of selected fields is NULL.


1. if you have defined both "dbhost" and "dbsock", mysql will prefer to use "dbsock", asterisk' behaviour was always the same. But now it is broken. If you specify "dbhost" res_config_mysql will ignore "dbsock" option. So your old config won't work anymore. Many people specify dbhost=localhost, dbsock=/tmp/mysql.sock, so i believe this should be reverted.

2. If any of fields in a row selected by realtime_mysql() is NULL, asterisk will segfault. This bug was added in patch 5881. res_config_mysql tryes to ast_strdupa() on mysql field, without checking it for NULL...

here is a piece of "bt full"

Thread 1 (process 12746):
#0  0xb6ed398c in realtime_mysql (database=0xb73e22c8 "asterisk", table=0xb73e21c8 "sip", ap=0xb73e23f0 "\004\233D&ASTERISK-1025;,?\025\b8$>&ASTERISK-1025;&ASTERISK-9299;\\\017\b\003")
   at res_config_mysql.c:170
       __old = 0x0
       __len = 2
       __new = 0xb73e1980 "0"
       result = (MYSQL_RES *) 0x81fc458
       row = (MYSQL_ROW) 0x8200448
       fields = (MYSQL_FIELD *) 0x81fe450
       numFields = 47
       i = 38
       valsz = 4
       sql = "SELECT * FROM sip WHERE name = '1303'", '\0' <repeats 443 times>, "&ASTERISK-1065;&ASTERISK-1099;&ASTERISK-1072;&ASTERISK-1025;", '\0' <repeats 12 times>, "k&ASTERISK-9284;&ASTERISK-1072;&ASTERISK-1025;\000\000\000\000\210\235\027\b`\225&ASTERISK-1046;&ASTERISK-1024;"
       buf = "1303", '\0' <repeats 31 times>, " \221>&ASTERISK-1025;X,&ASTERISK-1072;&ASTERISK-1025;&ASTERISK-1052;?&ASTERISK-1049;&ASTERISK-1025;\020G&ASTERISK-1096;&ASTERISK-1025;\000\000\000s\017\000\000\000\000\000\000\000&ASTERISK-1075;\223&ASTERISK-9286;&ASTERISK-1025;&ASTERISK-9283;\221>&ASTERISK-1025;\000\000\000\000\000\000\000\000ds>&ASTERISK-1025;&ASTERISK-9290;\232&ASTERISK-9283;\a,\207>&ASTERISK-1025;\020ii\r\024\000\000\000\220,&ASTERISK-1072;&ASTERISK-1025;\234&ASTERISK-1022;&ASTERISK-1163;&ASTERISK-1025;&ASTERISK-1077;?&ASTERISK-9286;&ASTERISK-1025;", '\0' <repeats 12 times>, "@\003\031\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\230#>&ASTERISK-1025;&ASTERISK-1094;&ASTERISK-9267;\030\b\204\036>&ASTERISK-1025;\230\036>&ASTERISK-1025;\207%&ASTERISK-1048;&ASTERISK-1025;\000\000\000\0000H&ASTERISK-1049;&ASTERISK-1025;\n\000\000\000hw\030\b\000\000\000\000\000\000\000\000&ASTERISK-1060;&ASTERISK-1060;&ASTERISK-1060;&ASTERISK-1060;\000\000\000\000\200$>&ASTERISK-1025;", '\0' <repeats 20 times>, "&ASTERISK-1096;\036>&ASTERISK-1025;0&ASTERISK-9276;\030\b,\207>&ASTERISK-1025;P\037"...
       stringp = 0x0
       chunk = 0x0
       op = 0xb6ed7178 " ="
       newparam = 0x0
       newval = 0xb73e255b "1303"
       var = (struct ast_variable *) 0x81face8
       prev = (struct ast_variable *) 0x82038a8
       __PRETTY_FUNCTION__ = "realtime_mysql"
#1  0x0808e4b6 in ast_load_realtime (family=0xb7442754 "sippeers") at config.c:1331
---Type <return> to continue, or q <return> to quit---
       res = <value optimized out>
       cur = dwarf2_read_address: Corrupted DWARF expression.


Attached patch is based on asterisk-addons/trunk Revision 365. It fixes both issues described here.
Comments:By: Joshua C. Colp (jcolp) 2007-04-16 08:17:02

Fixed in trunk as of revision 366. Peace!

By: Sergey Tamkovich (sergee) 2007-04-16 09:51:35

1 more segfault found.
In realtime_multi_mysql()

By: Sergey Tamkovich (sergee) 2007-04-16 10:31:49

it was last segfault in res_config_mysql i hope :)

By: Jason Parker (jparker) 2007-04-16 10:39:44

Fixed (more) in revision 367.