190201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich/* 290201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * Copyright (C) 2013 The Android Open Source Project 390201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * All rights reserved. 490201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * 590201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * Redistribution and use in source and binary forms, with or without 690201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * modification, are permitted provided that the following conditions 790201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * are met: 890201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * * Redistributions of source code must retain the above copyright 990201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * notice, this list of conditions and the following disclaimer. 1090201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * * Redistributions in binary form must reproduce the above copyright 1190201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * notice, this list of conditions and the following disclaimer in 1290201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * the documentation and/or other materials provided with the 1390201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * distribution. 1490201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * 1590201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1690201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1790201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1890201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1990201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2090201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2190201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 2290201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2390201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2490201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2590201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2690201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich * SUCH DAMAGE. 2790201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich */ 2890201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich 2990201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich#undef _FORTIFY_SOURCE 3090201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich#include <sys/select.h> 31eb847bc8666842a3cfc9c06e8458ad1abebebaf0Elliott Hughes#include "private/libc_logging.h" 3290201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich 337943df62f70f686b0c77532f6617b47255d75763Nick Kralevichextern "C" int __FD_ISSET_chk(int fd, fd_set* set, size_t set_size) { 3490201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich if (__predict_false(fd < 0)) { 35d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("FD_ISSET: file descriptor < 0", 0); 3690201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich } 3790201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich if (__predict_false(fd >= FD_SETSIZE)) { 38d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("FD_ISSET: file descriptor >= FD_SETSIZE", 0); 3990201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich } 407943df62f70f686b0c77532f6617b47255d75763Nick Kralevich if (__predict_false(set_size < sizeof(fd_set))) { 41d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("FD_ISSET: set is too small", 0); 427943df62f70f686b0c77532f6617b47255d75763Nick Kralevich } 4390201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich return FD_ISSET(fd, set); 4490201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich} 4590201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich 467943df62f70f686b0c77532f6617b47255d75763Nick Kralevichextern "C" void __FD_CLR_chk(int fd, fd_set* set, size_t set_size) { 4790201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich if (__predict_false(fd < 0)) { 48d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("FD_CLR: file descriptor < 0", 0); 4990201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich } 5090201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich if (__predict_false(fd >= FD_SETSIZE)) { 51d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("FD_CLR: file descriptor >= FD_SETSIZE", 0); 5290201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich } 537943df62f70f686b0c77532f6617b47255d75763Nick Kralevich if (__predict_false(set_size < sizeof(fd_set))) { 54d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("FD_CLR: set is too small", 0); 557943df62f70f686b0c77532f6617b47255d75763Nick Kralevich } 5690201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich FD_CLR(fd, set); 5790201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich} 5890201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich 597943df62f70f686b0c77532f6617b47255d75763Nick Kralevichextern "C" void __FD_SET_chk(int fd, fd_set* set, size_t set_size) { 6090201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich if (__predict_false(fd < 0)) { 61d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("FD_SET: file descriptor < 0", 0); 6290201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich } 6390201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich if (__predict_false(fd >= FD_SETSIZE)) { 64d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("FD_SET: file descriptor >= FD_SETSIZE", 0); 6590201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich } 667943df62f70f686b0c77532f6617b47255d75763Nick Kralevich if (__predict_false(set_size < sizeof(fd_set))) { 67d1eda33f012e46083b91e087fb79d14a5ce70f0eElliott Hughes __fortify_chk_fail("FD_SET: set is too small", 0); 687943df62f70f686b0c77532f6617b47255d75763Nick Kralevich } 6990201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich FD_SET(fd, set); 7090201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich} 71