Hi all,

This is more just for info than for anything else.

I spend several hours trying to understand why I was getting an invalid read
in the Valgrind report in calls to url_xtra(). The invalid read was always
of size 4, and was always happening always in the call to strlen() inside
the url_xtra() function (when calling nta_agent_create actually).

It seems that, when compiling with -O2 optimization the library (default),
that call to strlen() inside url_xtra() will read the string in chunks of 4
bytes instead of byte per byte. It is not happening if you use strlen() with
a char * in the code, but in url_hdup() the string to get the length from
comes to the function as a url_t (was coming from a url_string_t) which is
directly casted to char *. And seems the compiler doesn't understand that
very well, and tries to optimize it too much.

You can actually see what I mean running a simple stupid test:

The following code will issue in Valgrind/Memcheck report an Invalid Read of
Size 4 (length of the string is  18+1)
    char *contact = strdup("sip:127.0.0.1:5060");
    url_xtra((URL_STRING_MAKE(contact))->us_url);

While the following code doesn't issue any Invalid read error (has an empty
space at the end of the string, so length of the string is 19+1, which is
multiple of 4)
    char *contact = strdup("sip:127.0.0.1:5060 ");
    url_xtra((URL_STRING_MAKE(contact))->us_url);

Now, the output of url_xtra() is the correct one, and that error is just an
artifact of the optimized compilation, so you can just ignore it.


Cheers,
-Aleksander
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to