snprintf non-portable usage bug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I agree. I just created http://trac.pjsip.org/repos/ticket/1024 for
future reference.

On Wed, Jan 13, 2010 at 1:12 AM, Alfonso Ortega <alfonso at micasaverde.com> wrote:
> You need to fix the problem in uclibc. The offending lines are in
> libc/stdio/_vprintf.c. Just do a search for (null)
> On Jan 12, 2010, at 3:47 PM, Ted Merrill wrote:
>
>> Sorry, i'm also assuming that pj_strbuf() would be rewritten as:
>>
>> ? return (str->ptr ? str->ptr : "");
>>
>> -Ted Merrill
>>
>> On Tuesday 12 January 2010 03:43:04 pm Ted Merrill wrote:
>>>
>>> There are quite a few places in the pjsip code where it is assumed that
>>> an
>>> snprintf of "%.*s" will nicely print nothing if the supplied arguments
>>> are
>>> 0 and NULL.
>>> For example, in pjsua_acc.c there is:
>>> ? ? ? len = pj_ansi_snprintf(tmp, PJSIP_MAX_URL_SIZE,
>>>
>>> "<sip:%.*s%s%s%.*s%s:%d;transport=%s%.*s>%.*s", (int)acc->user_part.slen,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?acc->user_part.ptr,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(acc->user_part.slen? "@" : ""),
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?beginquote,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(int)via_addr->slen,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?via_addr->ptr,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?endquote,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?rport,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?tp->type_name,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(int)acc->cfg.contact_uri_params.slen,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?acc->cfg.contact_uri_params.ptr,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?(int)acc->cfg.contact_params.slen,
>>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?acc->cfg.contact_params.ptr);
>>> ... and by default acc->cfg.contact_uri_params and
>>> acc->cfg.contact_params
>>> both have 0 lengths and NULL pointers.
>>> This is very convenient when it works but sadly is not a feature of C
>>> libraries that one can count on, which makes the code less than portable.
>>> In my case, i'm using a version of uclibc that prints "(null)" whenever
>>> the
>>> pointer is NULL, regardless of the "precision" argument.
>>> Modifying uclibc is a possible work around for me, although it means i
>>> have
>>> to fork a version of uclibc which will make it hard to track their latest
>>> version... which won't make people i work with happy.
>>>
>>> I suggest that all such cases in the pj code be slightly rewritten so
>>> that
>>> "" is substituted where "ptr" is NULL.
>>> This can best be done with a wrapper inline function which we already
>>> have
>>> in pj/string.h !!! :
>>> PJ_INLINE(const char*) pj_strbuf( const pj_str_t *str )
>>> {
>>> ? return str->ptr;
>>> }
>>> used as:
>>> pj_strbuf(&acc->cfg.contact_params)
>>>
>>> To generalize, it would be better if the fields of pj_str_t were accessed
>>> only by standard access functions pj_strbuf() and pj_strlen() already
>>> provided in pj/string.h , and never directly as is the case in so much of
>>> the pj code... however, fixing the snprintfs would be a good start.
>>>
>>> Thanks a lot for pjsip,
>>> -Ted Merrill
>>
>>
>> _______________________________________________
>> Visit our blog: http://blog.pjsip.org
>>
>> pjsip mailing list
>> pjsip at lists.pjsip.org
>> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip at lists.pjsip.org
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>



-- 
Best regards,

 Benny



[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux