[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Remove tor_strclear(), and replace previous calls with memwipe().



commit cbd26157c52e27af16efcb474861eb4126085283
Author: Yawning Angel <yawning@xxxxxxxxxxxxxxx>
Date:   Tue Feb 17 18:53:33 2015 +0000

    Remove tor_strclear(), and replace previous calls with memwipe().
---
 src/common/util.c    |   10 ----------
 src/common/util.h    |    1 -
 src/or/rendservice.c |    4 ++--
 src/test/test_util.c |   21 ---------------------
 4 files changed, 2 insertions(+), 34 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index 442d57a..2c3a1a1 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -771,16 +771,6 @@ fast_memcmpstart(const void *mem, size_t memlen,
   return fast_memcmp(mem, prefix, plen);
 }
 
-/** Given a nul-terminated string s, set every character before the nul
- * to zero. */
-void
-tor_strclear(char *s)
-{
-  while (*s) {
-    *s++ = '\0';
-  }
-}
-
 /** Return a pointer to the first char of s that is not whitespace and
  * not a comment, or to the terminating NUL if no such character exists.
  */
diff --git a/src/common/util.h b/src/common/util.h
index ea774bd..783c2a1 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -209,7 +209,6 @@ int strcasecmpstart(const char *s1, const char *s2) ATTR_NONNULL((1,2));
 int strcmpend(const char *s1, const char *s2) ATTR_NONNULL((1,2));
 int strcasecmpend(const char *s1, const char *s2) ATTR_NONNULL((1,2));
 int fast_memcmpstart(const void *mem, size_t memlen, const char *prefix);
-void tor_strclear(char *s);
 
 void tor_strstrip(char *s, const char *strip) ATTR_NONNULL((1,2));
 long tor_parse_long(const char *s, int base, long min,
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 6c934c8..0368696 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -173,7 +173,7 @@ rend_authorized_client_free(rend_authorized_client_t *client)
     return;
   if (client->client_key)
     crypto_pk_free(client->client_key);
-  tor_strclear(client->client_name);
+  memwipe(client->client_name, 0, strlen(client->client_name));
   tor_free(client->client_name);
   memwipe(client->descriptor_cookie, 0, sizeof(client->descriptor_cookie));
   tor_free(client);
@@ -1052,7 +1052,7 @@ rend_service_load_auth_keys(rend_service_t *s, const char *hfname)
     abort_writing_to_file(open_hfile);
  done:
   if (client_keys_str) {
-    tor_strclear(client_keys_str);
+    memwipe(client_keys_str, 0, strlen(client_keys_str));
     tor_free(client_keys_str);
   }
   strmap_free(parsed_clients, rend_authorized_client_strmap_item_free);
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 9939bf4..41dd917 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -4111,26 +4111,6 @@ test_util_laplace(void *arg)
   ;
 }
 
-static void
-test_util_strclear(void *arg)
-{
-  static const char *vals[] = { "", "a", "abcdef", "abcdefgh", NULL };
-  int i;
-  char *v = NULL;
-  (void)arg;
-
-  for (i = 0; vals[i]; ++i) {
-    size_t n;
-    v = tor_strdup(vals[i]);
-    n = strlen(v);
-    tor_strclear(v);
-    tt_assert(tor_mem_is_zero(v, n+1));
-    tor_free(v);
-  }
- done:
-  tor_free(v);
-}
-
 #define UTIL_LEGACY(name)                                               \
   { #name, test_util_ ## name , 0, NULL, NULL }
 
@@ -4351,7 +4331,6 @@ struct testcase_t util_tests[] = {
   UTIL_LEGACY(di_ops),
   UTIL_TEST(round_to_next_multiple_of, 0),
   UTIL_TEST(laplace, 0),
-  UTIL_TEST(strclear, 0),
   UTIL_TEST(find_str_at_start_of_line, 0),
   UTIL_TEST(string_is_C_identifier, 0),
   UTIL_TEST(asprintf, 0),



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits