From 62c87a837463fdf09d9e7d1a605000c21f8da060 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Wed, 4 Apr 2018 13:01:37 +0200 Subject: Implement the wrapper function cleanse_buffer in masterpassword.c --- libsylph/masterpassword.c | 12 +++++++++--- libsylph/masterpassword.h | 1 + src/inputdialog.c | 6 ++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libsylph/masterpassword.c b/libsylph/masterpassword.c index b86f06b..2da6969 100644 --- a/libsylph/masterpassword.c +++ b/libsylph/masterpassword.c @@ -38,11 +38,17 @@ gchar *get_master_password(void) { return master_password; } -void unload_master_password(void) { - +void cleanse_buffer(void *buf, size_t len) { #if USE_SSL - OPENSSL_cleanse(master_password, strlen(master_password)); + OPENSSL_cleanse(buf, len); +#else + memset(buf, 0, len); /* better than nothing */ #endif +} + +void unload_master_password(void) { + + cleanse_buffer(master_password, strlen(master_password)); g_free(master_password); master_password = NULL; diff --git a/libsylph/masterpassword.h b/libsylph/masterpassword.h index 91f3793..cc32358 100644 --- a/libsylph/masterpassword.h +++ b/libsylph/masterpassword.h @@ -27,6 +27,7 @@ extern gchar *master_password; void set_master_password(const char *password); gchar *get_master_password(void); +void cleanse_buffer(void *buf, size_t len); void unload_master_password(void); gint mpes_string_prefix(const gchar *str); gboolean master_password_active(void); diff --git a/src/inputdialog.c b/src/inputdialog.c index 340e488..2510bbb 100644 --- a/src/inputdialog.c +++ b/src/inputdialog.c @@ -44,6 +44,7 @@ #include "filesel.h" #include "prefs_common.h" #include "gtkutils.h" +#include "masterpassword.h" #include "utils.h" #define DIALOG_WIDTH 420 @@ -182,11 +183,12 @@ gchar *input_dialog_set_new_password(guint max_attempts) NULL); if (pass1 != NULL && pass2 != NULL && strcmp(pass1, pass2) == 0) { - /* TODO: clear before free? */ + cleanse_buffer(pass2, strlen(pass2)); g_free(pass2); break; } - /* TODO: clear before free? */ + cleanse_buffer(pass1, strlen(pass1)); + cleanse_buffer(pass2, strlen(pass2)); g_free(pass2); g_free(pass1); pass1 = NULL; -- cgit v1.3