From 12b9e82db464e4e8b188b960e7439bd66a3eb03a Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 2 Oct 2011 14:03:47 +0000 Subject: [PATCH] Another utility function, to free a string containing sensitive data. git-svn-id: svn://svn.tartarus.org/sgt/putty@9319 cda61777-01e9-0310-a592-d414129be87e --- misc.c | 8 ++++++++ misc.h | 1 + 2 files changed, 9 insertions(+) diff --git a/misc.c b/misc.c index 8a9c7b11..636ca9f3 100644 --- a/misc.c +++ b/misc.c @@ -200,6 +200,14 @@ char *dupcat(const char *s1, ...) return p; } +void burnstr(char *string) /* sfree(str), only clear it first */ +{ + if (string) { + memset(string, 0, strlen(string)); + sfree(string); + } +} + /* * Do an sprintf(), but into a custom-allocated buffer. * diff --git a/misc.h b/misc.h index 49942aa5..9675e961 100644 --- a/misc.h +++ b/misc.h @@ -28,6 +28,7 @@ char *dupstr(const char *s); char *dupcat(const char *s1, ...); char *dupprintf(const char *fmt, ...); char *dupvprintf(const char *fmt, va_list ap); +void burnstr(char *string); char *fgetline(FILE *fp); -- 2.11.0