Re: New version of function mkdirhier()
On Thu, 2012-01-12 at 18:07:46 +0100, Svante Signell wrote:
> I'm currently creating a patch to make libtar build and stumbled on the
> function mkdirhier() in util.c. Since that function use not recommended
> and potentially dangerous functions like strlcpy and strsep I rewrote
> and generalized it using strchr and strncat.
How are those functions dangerous? And not recommended by whom? They
can cause portability issues but in this case the source provides
replacements when the system lacks them, so that's a non-issue. In
any case I have strong doubts upstream would accept such change.
Using strncat OTOH tends to confuse people, the len param is a
limiter on the src not the dest string. I see you made that mistake
on the code. This implies that when the string has the same len as
passed, the call is equivalent to its strcat counterpart, like in
“strncat(foo, "/", 1)”, the other cases would need their len argument
recomputed to pass the remaining dest space, which will end up with an
even larger and more complex implementation.
So I'd say, just switch the code to dynamically allocate the strings,
and let it use strlcat/strlcpy/strsep, etc.