160f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich/* 260f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * Copyright (C) 2013 The Android Open Source Project 360f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * All rights reserved. 460f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * 560f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * Redistribution and use in source and binary forms, with or without 660f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * modification, are permitted provided that the following conditions 760f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * are met: 860f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * * Redistributions of source code must retain the above copyright 960f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * notice, this list of conditions and the following disclaimer. 1060f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * * Redistributions in binary form must reproduce the above copyright 1160f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * notice, this list of conditions and the following disclaimer in 1260f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * the documentation and/or other materials provided with the 1360f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * distribution. 1460f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * 1560f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1660f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1760f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1860f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1960f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2060f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2160f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 2260f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2360f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2460f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2560f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2660f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich * SUCH DAMAGE. 2760f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich */ 2860f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich 2960f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich#undef _FORTIFY_SOURCE 3060f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich 3160f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich#include <stddef.h> 3260f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich#include <sys/socket.h> 33eb847bc8666842a3cfc9c06e8458ad1abebebaf0Elliott Hughes#include "private/libc_logging.h" 3460f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich 35658727e111ed6dee7be5239494f0764f7b1b02f8Dan Albertssize_t __recvfrom_chk(int socket, void* buf, size_t len, size_t buflen, 36658727e111ed6dee7be5239494f0764f7b1b02f8Dan Albert int flags, const struct sockaddr* src_addr, 37658727e111ed6dee7be5239494f0764f7b1b02f8Dan Albert socklen_t* addrlen) { 3860f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich if (__predict_false(len > buflen)) { 39d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("recvfrom: prevented write past end of buffer", 0); 4060f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich } 4160f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich 4260f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich return recvfrom(socket, buf, len, flags, src_addr, addrlen); 4360f4f9a5b99a0a66817f50edfc2194a49f8b5146Nick Kralevich} 44