diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2016-10-04 05:25:26 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2016-10-04 05:25:26 -0500 |
commit | 6b43a6a6c1f238b5ddea05964e19de86fe2fcda1 (patch) | |
tree | 0539ab871f01518a0eb26fad9ebe823025bdeaee | |
parent | 7515ce3fa8b30f7b7d67bc2a659e15276c0923d7 (diff) | |
download | gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.tar.gz gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.tar.bz2 gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.tar.xz gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.zip |
Add some _chk interfaces
-rw-r--r-- | stdio.c | 115 | ||||
-rw-r--r-- | stdlib.c | 6 | ||||
-rw-r--r-- | string.c | 38 |
3 files changed, 157 insertions, 2 deletions
@@ -1,3 +1,116 @@ +#include <assert.h> +#include <stdarg.h> #include <stdio.h> +#include <wchar.h> + +size_t __fread_chk(void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + assert(ptr != NULL); + assert(stream != NULL); + return fread(ptr, size, nmemb, stream); +} + +int __printf_chk(int flag, const char *format, ...) +{ + va_list argp; + int result; + + if(flag > 0) + { + assert(format != NULL); + } + + va_start(argp, format); + result = vprintf(format, argp); + va_end(argp); + + return result; +} + +int __fprintf_chk(FILE *stream, int flag, const char *format, ...) +{ + va_list argp; + int result; + + if(flag > 0) + { + assert(stream != NULL); + assert(format != NULL); + } + + va_start(argp, format); + result = vfprintf(stream, format, argp); + va_end(argp); + + return result; +} + +int __snprintf_chk(char *str, size_t size, int flag, size_t strlen, const char *format, ...) +{ + va_list argp; + int result; + + if(flag > 0) + { + assert(str != NULL); + assert(format != NULL); + } + // must always be done per LFS + assert(size <= strlen); + + va_start(argp, format); + result = vsnprintf(str, size, format, argp); + va_end(argp); + + return result; +} + +int __swprintf_chk(wchar_t *wcs, size_t maxlen, int flag, size_t wcslen, const wchar_t *format, ...) +{ + va_list argp; + int result; + + if(flag > 0) + { + assert(wcs != NULL); + assert(format != NULL); + } + // must always be done per LFS + assert(maxlen <= wcslen); + + va_start(argp, format); + result = vswprintf(wcs, maxlen, format, argp); + va_end(argp); + + return result; +} + +int __vasprintf_chk(char **strp, const char *fmt, va_list ap) +{ + assert(strp != NULL); + assert(fmt != NULL); + return vasprintf(strp, fmt, ap); +} + +int __vfprintf_chk(FILE *stream, int flag, const char *format, va_list ap) +{ + if(flag > 0) + { + assert(stream != NULL); + assert(format != NULL); + } + return vfprintf(stream, format, ap); +} + +int __vsnprintf_chk(char *str, size_t size, int flag, size_t strlen, const char *format, va_list ap) +{ + if(flag > 0) + { + assert(str != NULL); + assert(format != NULL); + } + // must always be done per LFS + assert(size <= strlen); + return vsnprintf(str, size, format, ap); +} -asm(".equ __IO_2_1_stdout_, _stdout"); @@ -1,6 +1,12 @@ #include <assert.h> // assert #include <stdlib.h> // strtod +char *__realpath_chk(const char *path, char *resolved_path) +{ + assert(path != NULL); + return realpath(path, resolved_path); +} + double __strtod_internal(const char *__nptr, char **__endptr, int __group) { assert(__group == 0); @@ -1,4 +1,40 @@ -#include <string.h> /* strndup */ +#include <assert.h> /* assert */ +#include <string.h> /* memcpy, strcpy, strncat, strndup */ + +/* "Checked" memcpy */ +void *__memcpy_chk(void *dest, const void *src, size_t len, size_t destlen) +{ + assert(dest != NULL); + assert(src != NULL); + assert(len <= destlen); + if(src < dest) + { + assert(!(src + len >= dest)); + } else { + assert(!(dest + len >= src)); + } + return memcpy(dest, src, len); +} + +/* "Checked" strncat */ +char *__strncat_chk(char *dest, const char *src, size_t n, size_t destlen) +{ + assert(dest != NULL); + assert(src != NULL); + assert(n <= destlen); + + return strncat(dest, src, n); +} + +/* "Checked" strcpy */ +char *__strcpy_chk(char *dest, const char *src, size_t destlen) +{ + assert(dest != NULL); + assert(src != NULL); + assert(strlen(src) < destlen); + + return strcpy(dest, src); +} /* Literally a useless __ alias. */ char *__strndup(const char *str, size_t count) |