[Olsr-dev] status tip + BSD

Sven-Ola Tuecke (spam-protected)
Thu Jan 29 13:00:43 CET 2009


Hey,

strncpy has a serious sematic flaw which makes it easy to invent bugs. I'm 
used to think "memcpy" instead of "strncpy" - which is normally the right 
thing to think[tm]. Better use something like this:

#if paranoid-about-runtime
#define strcpy(d, s) (d[sizeof(d) - 1] = 0, strncpy(d, s, sizeof(d) - 1))
#endif

// Sven-Ola

----- Original Message ----- 
From: "L. Aaron Kaplan" <(spam-protected)>
To: "Sven-Ola Tuecke" <(spam-protected)>
Cc: <(spam-protected)>
Sent: Thursday, January 29, 2009 11:27 AM
Subject: Re: [Olsr-dev] status tip + BSD


>
>
> Ok will do. But I prefer to have strcpy's etc out of the code somehow.
> Most of that was in the olsr_cfg.c file.
>
> I mean - there is a reason why OpenBSD (a.k.a. the most paranoid OS in 
> the world) does not like strcpy.
> I will back that out and rewrite it.
> But I might end up rewriting olsr_cfg.c if you dont mind....
>
> a.
>
>
>
> On Jan 29, 2009, at 8:41 AM, Sven-Ola Tuecke wrote:
>
>> As a P.S:
>>
>> Please revert completely + immediately. That really looks ugly:
>>
>> http://gredler.at/hg/olsrd/rev/c6a72905834a
>>
>> As a hint: strncpy() does not what you obviously think about that 
>> function.
>> The function will _omit_ the trailing zero, e.g. strncpy(dst, src,
>> strlen(src)) generally leads to very long strings because the ASCIIZ 
>> zero is
>> not copied to the destination buffer. Also suspicous:
>>
>> strscpy(autobuf->buf+autobuf->len, s, len /* make openbsd shut up */)
>>
>> Third parameter does not look like the strlen of s. strscpy is  unknown 
>> under
>> linux etc.
>>
>> // Sven-Ola
>>
>> Am Donnerstag 29 Januar 2009 08:29:41 schrieb Sven-Ola Tuecke:
>>> Hey aaron,
>>>
>>> that commit will break things. Please revise your strncpy() lines  for 
>>> +/- 1
>>> errors, e.g. the following line does effectively nothing and should  be
>>> removed or revised:
>>>
>>> strncpy(buffer->buf, "", 0);
>>>
>>> // Sven-Ola
>>>
>>> Am Mittwoch 28 Januar 2009 21:41:20 schrieb L. Aaron Kaplan:
>>>> hi!
>>>>
>>>> I tested tip on Mac OS X and OpenBSD.
>>>> I commited some stuff against tip . Mainly making it compilable in
>>>> OpenBSD.
>>>>
>>>> Please have a look at it in case you run VxWorks, FreeBSD, netBSD,
>>>> openBSD or Mac OS X.
>>>>
>>>> I tested the patches in a small network with triangle with:
>>>>
>>>> 1x OpenBSD 4.1, 1x Mac OS X 10.5, 1 x Freifunk firmware 1.36
>>>>
>>>> works.
>>>>
>>>>
>>>> a.
>>
>>
>>
>> -- 
>> Olsr-dev mailing list
>> (spam-protected)
>> http://lists.olsr.org/mailman/listinfo/olsr-dev 





More information about the Olsr-dev mailing list