[OpenSER-Devel] null socket crash

Bogdan-Andrei Iancu bogdan at voice-system.ro
Fri Oct 12 09:08:45 CEST 2007


Hi Juha,

in my opinion, the test should be done outside the function. If you call 
the function, it means you have a valid socket to convert (almost all 
libc function are built on this idea - like if you do a strlen() on a 
NULL pointer, it will crash ;) ).

Also the calling code may know better if the docket pointer can be null 
or not and to perform the proper checks (there are places where the 
function is used to convert sockets that are known not to be null and 
the test will be just useless).

So, in my opinion, the test should be done in lcr module and not inside 
the function.

regards,
bogdan

Juha Heinanen wrote:
> this morning i noticed a crash in lcr module.  i had added a permanent
> usrloc contact using ul_add mi function.  as result, i got into location
> table an entry where socket field had NULL value.
>
> one of things that lcr load_contacts function does is encoding of branch
> info into a string that contains among other things socket value.  it
> does socket to string conversion by calling socket_info.h function
> socket2str like this:
>
>     if (!socket2str(con->sock, at, &len)) {
> 	LM_ERR("Failed to convert socket to str\n");
> 	return 0;
>     }
>
> now if con->sock is null (0), the above socket2str call crashes
> openser.
>
> i could, of course, add a con->sock null test in lcr module before
> calling socket2str, but i feel that a more proper place for the test
> would be in socket2str function, because socket can be null and the
> function should thus be able to handle also such sockets.
>
> any opinions on this?
>
> -- juha
>
> _______________________________________________
> Devel mailing list
> Devel at openser.org
> http://openser.org/cgi-bin/mailman/listinfo/devel
>
>   




More information about the Devel mailing list