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

[or-cvs] replace malloc with tor_malloc; remove broken/unused crypto...



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home/arma/work/onion/cvs/src/common

Modified Files:
	crypto.c util.c util.h 
Log Message:
replace malloc with tor_malloc; remove broken/unused crypto_pk_set_key


Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- crypto.c	7 May 2003 18:30:46 -0000	1.18
+++ crypto.c	20 May 2003 06:37:34 -0000	1.19
@@ -91,9 +91,7 @@
 {
   crypto_pk_env_t *env;
   
-  env = (crypto_pk_env_t *)malloc(sizeof(crypto_pk_env_t));
-  if (!env)
-    return 0;
+  env = (crypto_pk_env_t *)tor_malloc(sizeof(crypto_pk_env_t));
   
   env->type = type;
   env->refs = 1;
@@ -185,9 +183,7 @@
   crypto_cipher_env_t *env;
   int iv_len, key_len;
   
-  env = (crypto_cipher_env_t *)malloc(sizeof(crypto_cipher_env_t));
-  if (!env)
-    return NULL;
+  env = (crypto_cipher_env_t *)tor_malloc(sizeof(crypto_cipher_env_t));
   
   env->type = type;
   env->key = NULL;
@@ -201,15 +197,15 @@
     /* This is not an openssl cipher */
     goto err;
   else {
-    env->aux = (unsigned char *)malloc(sizeof(EVP_CIPHER_CTX));
+    env->aux = (unsigned char *)tor_malloc(sizeof(EVP_CIPHER_CTX));
     EVP_CIPHER_CTX_init((EVP_CIPHER_CTX *)env->aux);
   }
 
-  if (iv_len && !(env->iv = (unsigned char *)malloc(iv_len)))
-    goto err;
+  if(iv_len)
+    env->iv = (unsigned char *)tor_malloc(iv_len);
 
-  if (key_len && !(env->key = (unsigned char *)malloc(key_len)))
-    goto err;
+  if(key_len)
+    env->key = (unsigned char *)tor_malloc(key_len);
   
   return env;
 err:
@@ -367,9 +363,7 @@
         BIO_set_close(b, BIO_NOCLOSE); /* so BIO_free doesn't free buf */
         BIO_free(b);
 
-        *dest = malloc(buf->length+1);
-        if(!*dest)
-          return -1;
+        *dest = tor_malloc(buf->length+1);
         memcpy(*dest, buf->data, buf->length);
         (*dest)[buf->length] = 0; /* null terminate it */
         *len = buf->length;
@@ -455,25 +449,6 @@
   }
 }
 
-int crypto_pk_set_key(crypto_pk_env_t *env, unsigned char *key)
-{
-  assert(env && key);
-  
-  switch(env->type) {
-    case CRYPTO_PK_RSA:
-    if (!env->key)
-      return -1;
-    /* XXX BUG XXX you can't memcpy an RSA, it's got a bunch of subpointers */
-    assert(0);
-    memcpy((void *)env->key, (void *)key, sizeof(RSA));
-    break;
-    default :
-    return -1;
-  }
-  
-  return 0;
-}
-
 int crypto_pk_cmp_keys(crypto_pk_env_t *a, crypto_pk_env_t *b) {
   int result; 
   
@@ -734,8 +709,7 @@
   if (!dh_param_p)
     init_dh_param();
     
-  if (!(res = malloc(sizeof(crypto_dh_env_t))))
-    goto err;
+  res = tor_malloc(sizeof(crypto_dh_env_t));
   res->dh = NULL;
 
   if (!(res->dh = DH_new()))

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- util.c	17 Apr 2003 02:03:55 -0000	1.4
+++ util.c	20 May 2003 06:37:34 -0000	1.5
@@ -7,6 +7,19 @@
 #include "util.h"
 #include "log.h"
 
+void *tor_malloc(size_t size) {
+  void *result;
+
+  result = malloc(size);
+
+  if(!result) {
+    log(LOG_ERR,"tor_malloc(): Out of memory. Dying.");
+    exit(1);
+  }
+
+  return result;
+}
+
 void 
 my_gettimeofday(struct timeval *timeval) 
 {

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- util.h	16 Apr 2003 17:04:57 -0000	1.1
+++ util.h	20 May 2003 06:37:34 -0000	1.2
@@ -7,6 +7,8 @@
 
 #include <sys/time.h>
 
+void *tor_malloc(size_t size);
+
 /* Same as gettimeofday, but no need to check exit value. */
 void my_gettimeofday(struct timeval *timeval);
 /* Returns the number of microseconds between start and end.  Requires that