소스 검색

add explicit_bzero implementation

maintainer's note: past sentiment was that, despite being imperfect
and unable to force clearing of all possible copies of sensitive data
(e.g. in registers, register spills, signal contexts left on the
stack, etc.) this function would be added if major implementations
agreed on it, which has happened -- several BSDs and glibc all include
it.
David Carlier 6 년 전
부모
커밋
05ac345f89
2개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      include/string.h
  2. 8 0
      src/string/explicit_bzero.c

+ 1 - 0
include/string.h

@@ -82,6 +82,7 @@ void *memccpy (void *__restrict, const void *__restrict, int, size_t);
 char *strsep(char **, const char *);
 size_t strlcat (char *, const char *, size_t);
 size_t strlcpy (char *, const char *, size_t);
+void explicit_bzero (void *, size_t);
 #endif
 
 #ifdef _GNU_SOURCE

+ 8 - 0
src/string/explicit_bzero.c

@@ -0,0 +1,8 @@
+#define _BSD_SOURCE
+#include <string.h>
+
+void explicit_bzero(void *d, size_t n)
+{
+	memset(d, 0, n);
+	__asm__ __volatile__ ("" : : "r"(d) : "memory");
+}