MINOR: chunks: always initialize the output chunk in get_trash_chunk()

The get_trash_chunk() function is convenient and is sometimes used even
to get a temporary string. While the chunk is initialized, the string
may contain some random garbage that some code might retrieve if it uses
chunk->str directly without checking ->len. This is what happened in checks
after commit 25e2ab5 (MEDIUM: checks: centralize error reporting). It's not
easy to guess it at first so better pre-initialize the string with a zero.
This commit is contained in:
Willy Tarreau 2013-12-11 17:32:08 +01:00
parent 89efaed6b6
commit 031ad23c47

View File

@ -33,7 +33,9 @@ static char *trash_buf2;
* type of conversion. Two chunks and their respective buffers are alternatively
* returned so that it is always possible to iterate data transformations without
* losing the data being transformed. The blocks are initialized to the size of
* a standard buffer, so they should be enough for everything.
* a standard buffer, so they should be enough for everything. For convenience,
* a zero is always emitted at the beginning of the string so that it may be
* used as an empty string as well.
*/
struct chunk *get_trash_chunk(void)
{
@ -47,6 +49,7 @@ struct chunk *get_trash_chunk(void)
trash_chunk = &trash_chunk1;
trash_buf = trash_buf1;
}
*trash_buf = 0;
chunk_init(trash_chunk, trash_buf, trash_size);
return trash_chunk;
}