[Bug libc/11319] dprintf doesn't handle errors properly

cvs-commit at gcc dot gnu.org sourceware-bugzilla@sourceware.org
Wed Jan 2 16:02:00 GMT 2019


https://sourceware.org/bugzilla/show_bug.cgi?id=11319

--- Comment #5 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  2d9837c1fbf4658f199eae02681f08f040dfe3a8 (commit)
      from  d5c6df0b0e021c1a3f17a0688cb5eea3f263b149 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=2d9837c1fbf4658f199eae02681f08f040dfe3a8

commit 2d9837c1fbf4658f199eae02681f08f040dfe3a8
Author: Gabriel F. T. Gomes <gabriel@inconstante.eti.br>
Date:   Wed Dec 19 18:01:14 2018 -0200

    Set behavior of sprintf-like functions with overlapping source and
destination

    According to ISO C99, passing the same buffer as source and destination
    to sprintf, snprintf, vsprintf, or vsnprintf has undefined behavior.
    Until the commit

      commit 4e2f43f842ef5e253cc23383645adbaa03cedb86
      Author: Zack Weinberg <zackw@panix.com>
      Date:   Wed Mar 7 14:32:03 2018 -0500

          Use PRINTF_FORTIFY instead of _IO_FLAGS2_FORTIFY (bug 11319)

    a call to sprintf or vsprintf with overlapping buffers, for instance
    vsprintf (buf, "%sTEXT", buf), would append `TEXT' into buf, while a
    call to snprintf or vsnprintf would override the contents of buf.
    After the aforementioned commit, the behavior of sprintf and vsprintf
    changed (so that they also override the contents of buf).

    This patch reverts this behavioral change, because it will likely break
    applications that rely on the previous behavior, even though it is
    undefined by ISO C.  As noted by Szabolcs Nagy, this is used in SPEC2017
    507.cactuBSSN_r/src/PUGH/PughUtils.c:

      sprintf(mess,"  Size:");
      for (i=0;i<dim+1;i++)
      {
          sprintf(mess,"%s %d",mess,pughGH->GFExtras[dim]->nsize[i]);
      }

    More important to notice is the fact that the overwriting of the
    destination buffer is not the only behavior affected by the refactoring.
    Before the refactoring, sprintf and vsprintf would use _IO_str_jumps,
    whereas __sprintf_chk and __vsprintf_chk would use _IO_str_chk_jumps.
    After the refactoring, all use _IO_str_chk_jumps, which would make
    sprintf and vsprintf report buffer overflows and terminate the program.
    This patch also reverts this behavior, by installing the appropriate
    jump table for each *sprintf functions.

    Apart from reverting the changes, this patch adds a test case that has
    the old behavior hardcoded, so that regressions are noticed if something
    else unintentionally changes the behavior.

    Tested for powerpc64le.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                  |   14 ++++++
 debug/sprintf_chk.c        |    4 ++
 debug/vsprintf_chk.c       |    4 ++
 libio/Makefile             |    7 +++-
 libio/iovsprintf.c         |   14 +++++-
 libio/libioP.h             |    6 ++-
 libio/tst-sprintf-chk-ub.c |    2 +
 libio/tst-sprintf-ub.c     |  102 ++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 149 insertions(+), 4 deletions(-)
 create mode 100644 libio/tst-sprintf-chk-ub.c
 create mode 100644 libio/tst-sprintf-ub.c

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list