]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: chunks: always initialize the output chunk in get_trash_chunk()
authorWilly Tarreau <w@1wt.eu>
Wed, 11 Dec 2013 16:32:08 +0000 (17:32 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 14 Dec 2013 15:02:18 +0000 (16:02 +0100)
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.

src/chunk.c

index f84ab10510e04954104a1b7787af7af5d6bd15c4..d7d8501d638101a49a130335e34fd0e2933e4270 100644 (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;
 }