[Announce] GnuPG 1.4 and 2.0 buffer overflow

Christian Biere christianbiere at gmx.de
Thu Nov 30 17:05:27 CET 2006


Werner Koch wrote:
> On Wed, 29 Nov 2006 17:32, christianbiere at gmx.de said:
> > Also replacement implementations for snprintf() have been around for years
> > and vsnprintf() can be used to write your own asprintf() in about 5 lines.
 
> va_copy is not a standard function/macro and actually missing on a lot
> of systems or again buggy.  Without that you can implement neither
> asprintf nor your proposed astrcat - unless you want to resort to
> realloc chains.

Just for the record: 99% of the time a local array to copy all members of
va_list to will be just fine. The freely available ISO C99 draft even
has example code for this in section 7.15. It's not C99-specific, it just
shows it's a well-known practice and that va_copy() is virtually redundant.

If you exceed this array, you'll have to resort to some dynamically allocated
array. In pathologic cases, you might need realloc for this array. Very simple
and straight-forward.

I write this just in case anyone thought one would use realloc() here for
appending strings.

-- 
Christian



More information about the Gnupg-devel mailing list