Back to index

glibc  2.9
vsprintf_chk.c
Go to the documentation of this file.
00001 /* Copyright (C) 1994, 1997, 1999-2003, 2004, 2006
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stdarg.h>
00021 #include <stdio.h>
00022 #include "../libio/libioP.h"
00023 #include "../libio/strfile.h"
00024 
00025 
00026 static int _IO_str_chk_overflow (_IO_FILE *fp, int c) __THROW;
00027 
00028 static int
00029 _IO_str_chk_overflow (fp, c)
00030      _IO_FILE *fp;
00031      int c;
00032 {
00033   /* When we come to here this means the user supplied buffer is
00034      filled.  */
00035   __chk_fail ();
00036 }
00037 
00038 
00039 static const struct _IO_jump_t _IO_str_chk_jumps =
00040 {
00041   JUMP_INIT_DUMMY,
00042   JUMP_INIT(finish, _IO_str_finish),
00043   JUMP_INIT(overflow, _IO_str_chk_overflow),
00044   JUMP_INIT(underflow, INTUSE(_IO_str_underflow)),
00045   JUMP_INIT(uflow, INTUSE(_IO_default_uflow)),
00046   JUMP_INIT(pbackfail, INTUSE(_IO_str_pbackfail)),
00047   JUMP_INIT(xsputn, INTUSE(_IO_default_xsputn)),
00048   JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
00049   JUMP_INIT(seekoff, INTUSE(_IO_str_seekoff)),
00050   JUMP_INIT(seekpos, _IO_default_seekpos),
00051   JUMP_INIT(setbuf, _IO_default_setbuf),
00052   JUMP_INIT(sync, _IO_default_sync),
00053   JUMP_INIT(doallocate, INTUSE(_IO_default_doallocate)),
00054   JUMP_INIT(read, _IO_default_read),
00055   JUMP_INIT(write, _IO_default_write),
00056   JUMP_INIT(seek, _IO_default_seek),
00057   JUMP_INIT(close, _IO_default_close),
00058   JUMP_INIT(stat, _IO_default_stat),
00059   JUMP_INIT(showmanyc, _IO_default_showmanyc),
00060   JUMP_INIT(imbue, _IO_default_imbue)
00061 };
00062 
00063 
00064 int
00065 ___vsprintf_chk (char *s, int flags, size_t slen, const char *format,
00066                va_list args)
00067 {
00068   _IO_strfile f;
00069   int ret;
00070 #ifdef _IO_MTSAFE_IO
00071   f._sbf._f._lock = NULL;
00072 #endif
00073 
00074   if (slen == 0)
00075     __chk_fail ();
00076 
00077   _IO_no_init (&f._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
00078   _IO_JUMPS ((struct _IO_FILE_plus *) &f._sbf) = &_IO_str_chk_jumps;
00079   s[0] = '\0';
00080   _IO_str_init_static_internal (&f, s, slen - 1, s);
00081 
00082   /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
00083      can only come from read-only format strings.  */
00084   if (flags > 0)
00085     f._sbf._f._flags2 |= _IO_FLAGS2_FORTIFY;
00086 
00087   ret = INTUSE(_IO_vfprintf) ((_IO_FILE *) &f._sbf, format, args);
00088 
00089   *f._sbf._f._IO_write_ptr = '\0';
00090   return ret;
00091 }
00092 ldbl_hidden_def (___vsprintf_chk, __vsprintf_chk)
00093 ldbl_strong_alias (___vsprintf_chk, __vsprintf_chk)