1 //===-- fortify-klibc.c ---------------------------------------------------===//
2 //
3 // The KLEE Symbolic Virtual Machine
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 /* Fortified versions of the libc functions defined in the klee-libc library */
11
12 #include "klee/klee.h"
13
14 #include <string.h>
15
16 #ifdef __APPLE__
17 /* macOS does not provide mempcpy in string.h */
18 void *mempcpy(void *destaddr, void const *srcaddr, size_t len);
19 #endif
20
__mempcpy_chk(void * dest,const void * src,size_t len,size_t destlen)21 void *__mempcpy_chk(void *dest, const void *src, size_t len, size_t destlen) {
22 if (len > destlen)
23 klee_report_error(__FILE__, __LINE__, "mempcpy overflow", "ptr.err");
24
25 return mempcpy(dest, src, len);
26 }
27
__stpcpy_chk(char * dest,const char * src,size_t destlen)28 char *__stpcpy_chk(char *dest, const char *src, size_t destlen) {
29 return stpcpy(dest, src);
30 }
31
__strcat_chk(char * dest,const char * src,size_t destlen)32 char *__strcat_chk(char *dest, const char *src, size_t destlen) {
33 return strcat(dest, src);
34 }
35
__strcpy_chk(char * dest,const char * src,size_t destlen)36 char *__strcpy_chk(char *dest, const char *src, size_t destlen) {
37 return strcpy(dest, src);
38 }
39
__strncpy_chk(char * s1,const char * s2,size_t n,size_t s1len)40 char *__strncpy_chk(char *s1, const char *s2, size_t n, size_t s1len) {
41 return strncpy(s1, s2, n);
42 }
43