stdio-common: Handle -1 buffer size in __sprintf_chk & co (bug 30039)
authorFlorian Weimer <fweimer@redhat.com>
Wed, 25 Jan 2023 07:01:00 +0000 (08:01 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 25 Jan 2023 07:01:00 +0000 (08:01 +0100)
commit0d50f477f47ba637b54fb03ac48d769ec4543e8d
tree598fbe050d8441a6152237d5442d2506ed846bf0
parent0674613e6652a46063756f162bdef88622b3bdbd
stdio-common: Handle -1 buffer size in __sprintf_chk & co (bug 30039)

This shows up as an assertion failure when sprintf is called with
a specifier like "%.8g" and libquadmath is linked in:

Fatal glibc error: printf_buffer_as_file.c:31
  (__printf_buffer_as_file_commit): assertion failed:
  file->stream._IO_write_ptr <= file->next->write_end

Fix this by detecting pointer wraparound in __vsprintf_internal
and saturate the addition to the end of the address space instead.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
debug/Makefile
debug/tst-sprintf-fortify-unchecked.c [new file with mode: 0644]
include/printf_buffer.h
libio/iovsprintf.c