Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20170715195541.3136-6-nwmcsween@gmail.com>
Date: Sat, 15 Jul 2017 19:55:41 +0000
From: Nathan McSween <nwmcsween@...il.com>
To: musl@...ts.openwall.com
Cc: Nathan McSween <nwmcsween@...il.com>
Subject: [RFC PATCH 5/5] string: add memsset a 'secure' memset and bsd explicit_bzero

---
 src/string/explicit_bzero.c |  9 +++++++++
 src/string/memsset.c        | 13 +++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 src/string/explicit_bzero.c
 create mode 100644 src/string/memsset.c

diff --git a/src/string/explicit_bzero.c b/src/string/explicit_bzero.c
new file mode 100644
index 00000000..497dd2bc
--- /dev/null
+++ b/src/string/explicit_bzero.c
@@ -0,0 +1,9 @@
+#define _BSD_SOURCE
+#include <string.h>
+
+void *__memsset(void *, int, size_t);
+
+void explicit_bzero(void *d, size_t n)
+{
+	__memsset(d, 0, n);
+}
diff --git a/src/string/memsset.c b/src/string/memsset.c
new file mode 100644
index 00000000..d4ab72a4
--- /dev/null
+++ b/src/string/memsset.c
@@ -0,0 +1,13 @@
+#include <string.h>
+
+#define hidden __attribute__((visibility("hidden")))
+
+hidden
+void *__memsset(void *d, int i, size_t n)
+{
+	memset(d, i, n);
+
+	__asm__ __volatile__("" : "=r" (d): "0" (d) : "memory");
+
+	return d;
+}
-- 
2.13.2

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.