aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-23 14:51:28 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-23 14:52:06 +0200
commit681f1e43afe9fdbc5c253ff603bcd9af447e7eb9 (patch)
tree13c9c436a4d9ba4276fef6db8f5a4134109e8d8e /src
parentchange inclusion guard pattern (diff)
downloadcerberus-681f1e43afe9fdbc5c253ff603bcd9af447e7eb9.tar.gz
cerberus-681f1e43afe9fdbc5c253ff603bcd9af447e7eb9.tar.bz2
cerberus-681f1e43afe9fdbc5c253ff603bcd9af447e7eb9.tar.xz
forcable wipe the passphrase
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r--src/cerberus.c36
-rw-r--r--src/cerberus.h2
2 files changed, 31 insertions, 7 deletions
diff --git a/src/cerberus.c b/src/cerberus.c
index a67a9ef..c70fb70 100644
--- a/src/cerberus.c
+++ b/src/cerberus.c
@@ -18,6 +18,8 @@
*/
#include "cerberus.h"
+#include <string.h>
+
/* TODO use log */
@@ -253,13 +255,7 @@ void do_login(int argc, char** argv)
alarm(0);
/* Wipe and free the passphrase from the memory */
- if (passphrase)
- {
- long i;
- for (i = 0; *(passphrase + i); i++)
- *(passphrase + i) = 0;
- free(passphrase);
- }
+ destroy_passphrase();
/* Reset terminal settings */
passphrase_reenable_echo();
@@ -340,3 +336,29 @@ char* read_passphrase(void)
}
#endif
+
+# pragma GCC optimize "-O0"
+
+
+/**
+ * Wipe and free the passphrase if it is allocated
+ */
+void destroy_passphrase(void)
+{
+ if (passphrase)
+ {
+ passphrase_wipe(passphrase, strlen(passphrase));
+ free(passphrase);
+ passphrase = NULL;
+ }
+}
+
+
+/**
+ * Wipe the passphrase when the program exits
+ */
+static __attribute__((destructor)) void passphrase_destructor(void)
+{
+ destroy_passphrase();
+}
+
diff --git a/src/cerberus.h b/src/cerberus.h
index cabc0e9..4737a97 100644
--- a/src/cerberus.h
+++ b/src/cerberus.h
@@ -59,6 +59,8 @@ char* read_passphrase(void);
#define read_passphrase NULL
#endif
+void destroy_passphrase(void) __attribute__((optimize("-O0")));
+
#endif