summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2016-10-04 05:25:26 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2016-10-04 05:25:26 -0500
commit6b43a6a6c1f238b5ddea05964e19de86fe2fcda1 (patch)
tree0539ab871f01518a0eb26fad9ebe823025bdeaee /string.c
parent7515ce3fa8b30f7b7d67bc2a659e15276c0923d7 (diff)
downloadgcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.tar.gz
gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.tar.bz2
gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.tar.xz
gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.zip
Add some _chk interfaces
Diffstat (limited to 'string.c')
-rw-r--r--string.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/string.c b/string.c
index 5bbb1b3..e50716a 100644
--- a/string.c
+++ b/string.c
@@ -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)