This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Implement C11 annex K?


On Wed, 13 Aug 2014, Russ Allbery wrote:

> If the answer is "use strcpy and strcat because this code is provably
> correct with them," I guess I understand your position, but if I somehow

stpcpy is better than strcpy and strcat here; repeated strcat, or strlcat 
as in your code, has quadratic overhead repeatedly looking for the end of 
the string being built up, whereas stpcpy returns the end pointer for use 
in the next stpcpy call.  However:

> messed up the length calculation logic, I would prefer to truncate the

It's not obvious what a safer version of the stpcpy code would look like, 
and the length calculation logic fails to allow for the sum of the lengths 
exceeding SIZE_MAX (e.g. from a long separator, or from several pointers 
to the same long string in the vector) (so resulting in buffer overflows 
from any version that doesn't check each write fits in the remaining 
space).  (This size calculation as written could feasibly overflow even on 
a 64-bit system; many such overflows are only realistic on 32-bit 
systems.)

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]