[asterisk-dev] chan_iax problem (was Re: Thoughts on Asterisk release management
Luigi Rizzo
rizzo at icir.org
Fri Sep 21 11:24:41 CDT 2007
On Fri, Sep 21, 2007 at 09:06:19AM -0500, Russell Bryant wrote:
> Luigi Rizzo wrote:
> <snip>
>
> Thank you very much for debugging the problem!
>
> > HOWEVER, the problem lies elsewhere, in this initialization in
> > chan_iax2.c::build_user() near line 9679:
> >
> > struct iax2_user tmp_user = {
> > .name = name,
> > };
> >
> > (there are several other instances like this).
> >
> > The field "name" is an AST_STRING_FIELD, and for some
> > reason, at least with my compiler (gcc 2.95 on FreeBSD 4.11)
> > the initialization leaves it to NULL instead of setting the
> > correct value.
> >
> > Why that happens, i have no idea; however it
> > is really something that we should figure out because it is critical.
> > Patching ast_str_hash() to handle the NULL argument will prevent
> > the crash but not fix the problem.
>
> Well, this is certainly bizarre. We rely on initializer lists like this all
> over the place in Asterisk. I have never seen one not work. Perhaps it doesn't
> like that tmp_user.name is of type ast_string_field and name is const char *?
> (ast_string_field is just a typedef to const char * ...)
For as bizarre as it might be, apparently the problem is related
to the use of a zero-sized array in front of the field_list:
(see stringfields.h):
ast_string_field __begin_field[0]; \
field_list \
ast_string_field __end_field[0]; \
struct ast_string_field_mgr __field_mgr
If i move the 'name' element in iax2_user to the second position
in the string fields, it gets initialized correctly (but then i
have panics elsewhere, perhaps on an iax2_peer object)
As a temporary workaround i have changed _begin_field and __end_field
to size 1 in my system and this appears to fix things (in fact,
just changing __begin_field seems enough, and so we could probably
solve the problem by putting the field_mgr elements around the
field_list and use them as markers).
It may well be a bug in gcc 2.95 so i am not asking to put bandaids
in the tree (but at least a note in the file could be useful),
but if i remember well the handling of zero-sized arrays is a bit
of a grey area in C, so we should probably expect some trouble with
this structure across different compilers.
cheers
luigi
More information about the asterisk-dev
mailing list