]> git.ipfire.org Git - thirdparty/glibc.git/commit - stdio-common/vfprintf-internal.c
stdio: Remove memory leak from multibyte convertion [BZ#25691]
authorFlorian Weimer <fweimer@redhat.com>
Thu, 19 Mar 2020 21:32:28 +0000 (18:32 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 20 Mar 2020 14:02:38 +0000 (11:02 -0300)
commit3cc4a8367c23582b7db14cf4e150e4068b7fd461
tree15d2a2d398477b12d4f808a4412ef1ca1fa52a0b
parent39a05214fe14ff722d4d92e697fb71ff15e84e70
stdio: Remove memory leak from multibyte convertion [BZ#25691]

This is an updated version of a previous patch [1] with the
following changes:

  - Use compiler overflow builtins on done_add_func function.
  - Define the scratch +utstring_converted_wide_string using
    CHAR_T.
  - Added a testcase and mention the bug report.

Both default and wide printf functions might leak memory when
manipulate multibyte characters conversion depending of the size
of the input (whether __libc_use_alloca trigger or not the fallback
heap allocation).

This patch fixes it by removing the extra memory allocation on
string formatting with conversion parts.

The testcase uses input argument size that trigger memory leaks
on unpatched code (using a scratch buffer the threashold to use
heap allocation is lower).

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
[1] https://sourceware.org/pipermail/libc-alpha/2017-June/082098.html
stdio-common/vfprintf-internal.c