Updated to fedora-glibc-20090427T1419
[glibc/history.git] / debug / vsprintf_chk.c
blob22cb2c7ad9422ed7909e817d49a1eebb6d6a5284
1 /* Copyright (C) 1994, 1997, 1999-2003, 2004, 2006, 2009
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <stdarg.h>
21 #include <stdio.h>
22 #include "../libio/libioP.h"
23 #include "../libio/strfile.h"
26 static int _IO_str_chk_overflow (_IO_FILE *fp, int c) __THROW;
28 static int
29 _IO_str_chk_overflow (fp, c)
30 _IO_FILE *fp;
31 int c;
33 /* When we come to here this means the user supplied buffer is
34 filled. */
35 __chk_fail ();
39 static const struct _IO_jump_t _IO_str_chk_jumps =
41 JUMP_INIT_DUMMY,
42 JUMP_INIT(finish, _IO_str_finish),
43 JUMP_INIT(overflow, _IO_str_chk_overflow),
44 JUMP_INIT(underflow, INTUSE(_IO_str_underflow)),
45 JUMP_INIT(uflow, INTUSE(_IO_default_uflow)),
46 JUMP_INIT(pbackfail, INTUSE(_IO_str_pbackfail)),
47 JUMP_INIT(xsputn, INTUSE(_IO_default_xsputn)),
48 JUMP_INIT(xsgetn, INTUSE(_IO_default_xsgetn)),
49 JUMP_INIT(seekoff, INTUSE(_IO_str_seekoff)),
50 JUMP_INIT(seekpos, _IO_default_seekpos),
51 JUMP_INIT(setbuf, _IO_default_setbuf),
52 JUMP_INIT(sync, _IO_default_sync),
53 JUMP_INIT(doallocate, INTUSE(_IO_default_doallocate)),
54 JUMP_INIT(read, _IO_default_read),
55 JUMP_INIT(write, _IO_default_write),
56 JUMP_INIT(seek, _IO_default_seek),
57 JUMP_INIT(close, _IO_default_close),
58 JUMP_INIT(stat, _IO_default_stat),
59 JUMP_INIT(showmanyc, _IO_default_showmanyc),
60 JUMP_INIT(imbue, _IO_default_imbue)
64 int
65 ___vsprintf_chk (char *s, int flags, size_t slen, const char *format,
66 va_list args)
68 _IO_strfile f;
69 int ret;
70 #ifdef _IO_MTSAFE_IO
71 f._sbf._f._lock = NULL;
72 #endif
74 if (slen == 0)
75 __chk_fail ();
77 _IO_no_init (&f._sbf._f, _IO_USER_LOCK, -1, NULL, NULL);
78 _IO_JUMPS (&f._sbf) = &_IO_str_chk_jumps;
79 s[0] = '\0';
80 _IO_str_init_static_internal (&f, s, slen - 1, s);
82 /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
83 can only come from read-only format strings. */
84 if (flags > 0)
85 f._sbf._f._flags2 |= _IO_FLAGS2_FORTIFY;
87 ret = INTUSE(_IO_vfprintf) (&f._sbf._f, format, args);
89 *f._sbf._f._IO_write_ptr = '\0';
90 return ret;
92 ldbl_hidden_def (___vsprintf_chk, __vsprintf_chk)
93 ldbl_strong_alias (___vsprintf_chk, __vsprintf_chk)