giada - new release

James Cowgill jcowgill at debian.org
Wed Jan 17 16:19:23 UTC 2018


Hi,

On 17/01/18 15:42, Jaromír Mikeš wrote:
> ​Hi,
> 
> giada unfortunately fail to build on some archs ... I already informed
> upstream but not answer yet.
> Can someone look if fixing this is rather trivial or complicated.
> 
> https://buildd.debian.org/status/package.php?p=giada

The entire function for reference:
> std::string gu_format(const char* format, ...)
> {
> 	va_list args;
> 
> 	/* Compute the size of the new expanded string (i.e. with replacement taken
> 	into account). */
> 
> 	size_t size = vsnprintf(nullptr, 0, format, args);
> 
> 	/* Create a new temporary char array to hold the new expanded string. */
> 
> 	std::unique_ptr<char[]> tmp(new char[size]);
> 
> 	/* Fill the temporary string with the formatted data. */
> 
>   va_start(args, format);
> 	vsprintf(tmp.get(), format, args);
>   va_end(args);
>   
>  	return string(tmp.get(), tmp.get() + size - 1);	
> }

This line (the one the error complains about) reads the uninitialized
args and invokes undefined behavior:
> size_t size = vsnprintf(nullptr, 0, format, args);

It needs to be surrounded in va_start, va_end block.

The second subtle error is that vsnprintf returns the size _excluding
the null byte_. This will cause the vsprintf call to overflow the buffer
by 1 byte.

This might work (untested):
 va_start(args, format);
 size_t size = vsnprintf(nullptr, 0, format, args) + 1;
 va_end(args);

Some alternative implementations. The varardic template solution (the
third one) is similar to this code (and the one I like the most):
https://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf

James

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-multimedia-maintainers/attachments/20180117/485b4340/attachment.sig>


More information about the pkg-multimedia-maintainers mailing list