Another utility function, to free a string containing sensitive data.
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 2 Oct 2011 14:03:47 +0000 (14:03 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 2 Oct 2011 14:03:47 +0000 (14:03 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/putty@9319 cda61777-01e9-0310-a592-d414129be87e

misc.c
misc.h

diff --git a/misc.c b/misc.c
index 8a9c7b1..636ca9f 100644 (file)
--- 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 49942aa..9675e96 100644 (file)
--- 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);