1*0c47b9c2SKyle Evans /*-
2*0c47b9c2SKyle Evans *
3*0c47b9c2SKyle Evans * SPDX-License-Identifier: BSD-2-Clause
4*0c47b9c2SKyle Evans *
5*0c47b9c2SKyle Evans * Copyright (c) 2006 The NetBSD Foundation, Inc.
6*0c47b9c2SKyle Evans * All rights reserved.
7*0c47b9c2SKyle Evans *
8*0c47b9c2SKyle Evans * This code is derived from software contributed to The NetBSD Foundation
9*0c47b9c2SKyle Evans * by Christos Zoulas.
10*0c47b9c2SKyle Evans *
11*0c47b9c2SKyle Evans * Redistribution and use in source and binary forms, with or without
12*0c47b9c2SKyle Evans * modification, are permitted provided that the following conditions
13*0c47b9c2SKyle Evans * are met:
14*0c47b9c2SKyle Evans * 1. Redistributions of source code must retain the above copyright
15*0c47b9c2SKyle Evans * notice, this list of conditions and the following disclaimer.
16*0c47b9c2SKyle Evans * 2. Redistributions in binary form must reproduce the above copyright
17*0c47b9c2SKyle Evans * notice, this list of conditions and the following disclaimer in the
18*0c47b9c2SKyle Evans * documentation and/or other materials provided with the distribution.
19*0c47b9c2SKyle Evans *
20*0c47b9c2SKyle Evans * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21*0c47b9c2SKyle Evans * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22*0c47b9c2SKyle Evans * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23*0c47b9c2SKyle Evans * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24*0c47b9c2SKyle Evans * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25*0c47b9c2SKyle Evans * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26*0c47b9c2SKyle Evans * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27*0c47b9c2SKyle Evans * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28*0c47b9c2SKyle Evans * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29*0c47b9c2SKyle Evans * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30*0c47b9c2SKyle Evans * POSSIBILITY OF SUCH DAMAGE.
31*0c47b9c2SKyle Evans */
32*0c47b9c2SKyle Evans
33*0c47b9c2SKyle Evans #include <string.h>
34*0c47b9c2SKyle Evans
35*0c47b9c2SKyle Evans #include <ssp/string.h>
36*0c47b9c2SKyle Evans #undef mempcpy
37*0c47b9c2SKyle Evans
38*0c47b9c2SKyle Evans void *
__mempcpy_chk(void * __restrict dst,const void * __restrict src,size_t len,size_t slen)39*0c47b9c2SKyle Evans __mempcpy_chk(void * __restrict dst, const void * __restrict src, size_t len,
40*0c47b9c2SKyle Evans size_t slen)
41*0c47b9c2SKyle Evans {
42*0c47b9c2SKyle Evans if (len > slen)
43*0c47b9c2SKyle Evans __chk_fail();
44*0c47b9c2SKyle Evans
45*0c47b9c2SKyle Evans if (__ssp_overlap(src, dst, len))
46*0c47b9c2SKyle Evans __chk_fail();
47*0c47b9c2SKyle Evans
48*0c47b9c2SKyle Evans return (mempcpy(dst, src, len));
49*0c47b9c2SKyle Evans }
50