changeset 2291:2af950507af5

password shredding Justus had written a patch for this, but the list archive didn't want to disgorge it, so I wrote one.
author corvid <corvid@lavabit.com>
date Thu, 29 Sep 2011 15:59:46 +0000
parents 51f968db9dc8
children 726cc2774731
files dlib/dlib.c dlib/dlib.h
diffstat 2 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dlib/dlib.c	Thu Sep 29 15:48:11 2011 +0000
+++ b/dlib/dlib.c	Thu Sep 29 15:59:46 2011 +0000
@@ -134,6 +134,15 @@
 }
 
 /*
+ * Clear the contents of the string
+ */
+void dStrshred(char *s)
+{
+   if (s)
+      memset(s, 0, strlen(s));
+}
+
+/*
  * Return a new string of length 'len' filled with 'c' characters
  */
 char *dStrnfill(size_t len, char c)
@@ -336,6 +345,15 @@
 }
 
 /*
+ * Clear a Dstr.
+ */
+void dStr_shred (Dstr *ds)
+{
+   if (ds && ds->sz > 0)
+      memset(ds->str, '\0', ds->sz);
+}
+
+/*
  * Erase a substring.
  */
 void dStr_erase (Dstr *ds, int pos_0, int len)
--- a/dlib/dlib.h	Thu Sep 29 15:48:11 2011 +0000
+++ b/dlib/dlib.h	Thu Sep 29 15:59:46 2011 +0000
@@ -87,6 +87,7 @@
 char *dStrnfill(size_t len, char c);
 char *dStrsep(char **orig, const char *delim);
 char *dStristr(const char *haystack, const char *needle);
+void dStrshred(char *s);
 
 /* these are in POSIX 2001. Could be implemented if a port requires it */
 #define dStrcasecmp strcasecmp
@@ -114,6 +115,7 @@
 void dStr_insert (Dstr *ds, int pos_0, const char *s);
 void dStr_insert_l (Dstr *ds, int pos_0, const char *s, int l);
 void dStr_truncate (Dstr *ds, int len);
+void dStr_shred (Dstr *ds);
 void dStr_erase (Dstr *ds, int pos_0, int len);
 void dStr_vsprintfa (Dstr *ds, const char *format, va_list argp);
 void dStr_vsprintf (Dstr *ds, const char *format, va_list argp);