14ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay/* 24ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * Copyright (C) 2015 The Android Open Source Project 34ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * All rights reserved. 44ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * 54ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * Redistribution and use in source and binary forms, with or without 64ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * modification, are permitted provided that the following conditions 74ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * are met: 84ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * * Redistributions of source code must retain the above copyright 94ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * notice, this list of conditions and the following disclaimer. 104ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * * Redistributions in binary form must reproduce the above copyright 114ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * notice, this list of conditions and the following disclaimer in 124ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * the documentation and/or other materials provided with the 134ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * distribution. 144ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * 154ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 164ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 174ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 184ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 194ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 204ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 214ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 224ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 234ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 244ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 254ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 264ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay * SUCH DAMAGE. 274ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay */ 284ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay 294ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay#undef _FORTIFY_SOURCE 304ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay#include <string.h> 314ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay#include "private/libc_logging.h" 324ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay 334ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micayextern "C" void* __memrchr_chk(const void* s, int c, size_t n, size_t buf_size) { 344ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay if (__predict_false(n > buf_size)) { 354ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay __fortify_chk_fail("memrchr: prevented read past end of buffer", 0); 364ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay } 374ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay 384ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay return memrchr(s, c, n); 394ae773633aac9ceba5ec62bb8e1aa22c3c56ebdeDaniel Micay} 40