Blame debug/vsprintf_chk.c

Packit 6c4009
/* Copyright (C) 1994-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <stdarg.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include "../libio/libioP.h"
Packit 6c4009
#include "../libio/strfile.h"
Packit 6c4009
Packit 6c4009
Packit 6c4009
static int _IO_str_chk_overflow (FILE *fp, int c) __THROW;
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
_IO_str_chk_overflow (FILE *fp, int c)
Packit 6c4009
{
Packit 6c4009
  /* When we come to here this means the user supplied buffer is
Packit 6c4009
     filled.  */
Packit 6c4009
  __chk_fail ();
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static const struct _IO_jump_t _IO_str_chk_jumps libio_vtable =
Packit 6c4009
{
Packit 6c4009
  JUMP_INIT_DUMMY,
Packit 6c4009
  JUMP_INIT(finish, _IO_str_finish),
Packit 6c4009
  JUMP_INIT(overflow, _IO_str_chk_overflow),
Packit 6c4009
  JUMP_INIT(underflow, _IO_str_underflow),
Packit 6c4009
  JUMP_INIT(uflow, _IO_default_uflow),
Packit 6c4009
  JUMP_INIT(pbackfail, _IO_str_pbackfail),
Packit 6c4009
  JUMP_INIT(xsputn, _IO_default_xsputn),
Packit 6c4009
  JUMP_INIT(xsgetn, _IO_default_xsgetn),
Packit 6c4009
  JUMP_INIT(seekoff, _IO_str_seekoff),
Packit 6c4009
  JUMP_INIT(seekpos, _IO_default_seekpos),
Packit 6c4009
  JUMP_INIT(setbuf, _IO_default_setbuf),
Packit 6c4009
  JUMP_INIT(sync, _IO_default_sync),
Packit 6c4009
  JUMP_INIT(doallocate, _IO_default_doallocate),
Packit 6c4009
  JUMP_INIT(read, _IO_default_read),
Packit 6c4009
  JUMP_INIT(write, _IO_default_write),
Packit 6c4009
  JUMP_INIT(seek, _IO_default_seek),
Packit 6c4009
  JUMP_INIT(close, _IO_default_close),
Packit 6c4009
  JUMP_INIT(stat, _IO_default_stat),
Packit 6c4009
  JUMP_INIT(showmanyc, _IO_default_showmanyc),
Packit 6c4009
  JUMP_INIT(imbue, _IO_default_imbue)
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
___vsprintf_chk (char *s, int flags, size_t slen, const char *format,
Packit 6c4009
		 va_list args)
Packit 6c4009
{
Packit 6c4009
  _IO_strfile f;
Packit 6c4009
  int ret;
Packit 6c4009
#ifdef _IO_MTSAFE_IO
Packit 6c4009
  f._sbf._f._lock = NULL;
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
  if (slen == 0)
Packit 6c4009
    __chk_fail ();
Packit 6c4009
Packit 6c4009
  _IO_no_init (&f._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
Packit 6c4009
  _IO_JUMPS (&f._sbf) = &_IO_str_chk_jumps;
Packit 6c4009
  s[0] = '\0';
Packit 6c4009
  _IO_str_init_static_internal (&f, s, slen - 1, s);
Packit 6c4009
Packit 6c4009
  /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
Packit 6c4009
     can only come from read-only format strings.  */
Packit 6c4009
  if (flags > 0)
Packit 6c4009
    f._sbf._f._flags2 |= _IO_FLAGS2_FORTIFY;
Packit 6c4009
Packit 6c4009
  ret = _IO_vfprintf (&f._sbf._f, format, args);
Packit 6c4009
Packit 6c4009
  *f._sbf._f._IO_write_ptr = '\0';
Packit 6c4009
  return ret;
Packit 6c4009
}
Packit 6c4009
ldbl_hidden_def (___vsprintf_chk, __vsprintf_chk)
Packit 6c4009
ldbl_strong_alias (___vsprintf_chk, __vsprintf_chk)