[Freeswitch-users] BUG in FS C-Function: switch_separate_string(-)

king2kin xing2kin at yahoo.com
Sat Sep 10 09:02:37 MSD 2011


Hi folks,

I think that switch_separate_string(-) has a bug in splitting a string into array by a token: 

While parsing a char string into an array, [switch_separate_string(-)] always treats some substrings (which start with backslash char '\') as escaped chars, 

for example: even though char '\' has been escaped inside a constant string {"status=10&path=c:\\temp\\log\\&name=tom"}, [switch_separate_string(-)] treats its substring "\t" AS a single tab char; and substring "\&" AS a single char '&'. This result is definitely wrong!

Here is an example that I tried on windows 2003 server:

-- src codes:

int nParams = 0;
char* params[64] = {0};

char mystr[] = "status=10&path=c:\\temp\\log\\&name=tom";

switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mystr: %s\n", mystr);
nParams = switch_separate_string(mystr, '&', params, (sizeof(params) / sizeof(params[0])));    
for (i=0; i < nParams; i++)
{
    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%d]: {%s}\n", i, params[i]);
}

-- printed log info:

2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:981 mystr: status=10&path=c:\temp\log\&name=tom
2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:985 [0]: {status=10}
2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:985 [1]: {path=c:    emp\log&name=tom}

My comment: the above string 'mystr' is supposed to be parsed into a 3-element array {10, path=c:\temp\log\, tom}; however, [switch_separate_string(-)]parsed it into a 2-element array {10, path=c:    emp\log&name=tom}. 


x.k. 





Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list