19b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich/* 29b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * Copyright (C) 2012 The Android Open Source Project 39b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * All rights reserved. 49b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * 59b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * Redistribution and use in source and binary forms, with or without 69b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * modification, are permitted provided that the following conditions 79b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * are met: 89b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * * Redistributions of source code must retain the above copyright 99b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * notice, this list of conditions and the following disclaimer. 109b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * * Redistributions in binary form must reproduce the above copyright 119b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * notice, this list of conditions and the following disclaimer in 129b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * the documentation and/or other materials provided with the 139b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * distribution. 149b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * 159b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 169b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 179b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 189b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 199b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 209b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 219b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 229b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 239b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 249b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 259b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 269b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * SUCH DAMAGE. 279b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich */ 289b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich 299b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich#include <stdio.h> 309b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich#include <stdarg.h> 319b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich 329b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich/* 339b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * Runtime implementation of __builtin____sprintf_chk. 349b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * 359b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * See 369b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html 379b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html 389b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * for details. 399b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * 409b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * This sprintf check is called if _FORTIFY_SOURCE is defined and 419b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich * greater than 0. 429b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich */ 439b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevichint __sprintf_chk( 449b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich char *dest, 459b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich int flags, 469b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich size_t dest_len_from_compiler, 479b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich const char *format, ...) 489b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich{ 499b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich va_list va; 509b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich int retval; 519b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich 529b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich va_start(va, format); 539b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich retval = __vsprintf_chk(dest, flags, 549b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich dest_len_from_compiler, format, va); 559b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich va_end(va); 569b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich 579b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich return retval; 589b549c39c938f54680f282c21e6885f53254bfb0Nick Kralevich} 59