Blame debug/vsnprintf_chk.c

Packit Service 82fcde
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <stdarg.h>
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include "../libio/libioP.h"
Packit Service 82fcde
#include "../libio/strfile.h"
Packit Service 82fcde
Packit Service 82fcde
extern const struct _IO_jump_t _IO_strn_jumps libio_vtable attribute_hidden;
Packit Service 82fcde
Packit Service 82fcde
/* Write formatted output into S, according to the format
Packit Service 82fcde
   string FORMAT, writing no more than MAXLEN characters.  */
Packit Service 82fcde
/* VARARGS5 */
Packit Service 82fcde
int
Packit Service 82fcde
___vsnprintf_chk (char *s, size_t maxlen, int flags, size_t slen,
Packit Service 82fcde
		  const char *format, va_list args)
Packit Service 82fcde
{
Packit Service 82fcde
  /* XXX Maybe for less strict version do not fail immediately.
Packit Service 82fcde
     Though, maxlen is supposed to be the size of buffer pointed
Packit Service 82fcde
     to by s, so a conforming program can't pass such maxlen
Packit Service 82fcde
     to *snprintf.  */
Packit Service 82fcde
  if (__glibc_unlikely (slen < maxlen))
Packit Service 82fcde
    __chk_fail ();
Packit Service 82fcde
Packit Service 82fcde
  _IO_strnfile sf;
Packit Service 82fcde
  int ret;
Packit Service 82fcde
#ifdef _IO_MTSAFE_IO
Packit Service 82fcde
  sf.f._sbf._f._lock = NULL;
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
  /* We need to handle the special case where MAXLEN is 0.  Use the
Packit Service 82fcde
     overflow buffer right from the start.  */
Packit Service 82fcde
  if (maxlen == 0)
Packit Service 82fcde
    {
Packit Service 82fcde
      s = sf.overflow_buf;
Packit Service 82fcde
      maxlen = sizeof (sf.overflow_buf);
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  _IO_no_init (&sf.f._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
Packit Service 82fcde
  _IO_JUMPS (&sf.f._sbf) = &_IO_strn_jumps;
Packit Service 82fcde
  s[0] = '\0';
Packit Service 82fcde
Packit Service 82fcde
  /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
Packit Service 82fcde
     can only come from read-only format strings.  */
Packit Service 82fcde
  if (flags > 0)
Packit Service 82fcde
    sf.f._sbf._f._flags2 |= _IO_FLAGS2_FORTIFY;
Packit Service 82fcde
Packit Service 82fcde
  _IO_str_init_static_internal (&sf.f, s, maxlen - 1, s);
Packit Service 82fcde
  ret = _IO_vfprintf (&sf.f._sbf._f, format, args);
Packit Service 82fcde
Packit Service 82fcde
  if (sf.f._sbf._f._IO_buf_base != sf.overflow_buf)
Packit Service 82fcde
    *sf.f._sbf._f._IO_write_ptr = '\0';
Packit Service 82fcde
  return ret;
Packit Service 82fcde
}
Packit Service 82fcde
ldbl_hidden_def (___vsnprintf_chk, __vsnprintf_chk)
Packit Service 82fcde
ldbl_strong_alias (___vsnprintf_chk, __vsnprintf_chk)