prf handles zero-length allocations graceful
authorMartin Willi <martin@strongswan.org>
Wed, 29 Oct 2008 14:12:54 +0000 (14:12 -0000)
committerMartin Willi <martin@strongswan.org>
Wed, 29 Oct 2008 14:12:54 +0000 (14:12 -0000)
src/libstrongswan/crypto/prf_plus.c

index 6b10420..b5072f8 100644 (file)
@@ -96,9 +96,16 @@ static void get_bytes(private_prf_plus_t *this, size_t length, u_int8_t *buffer)
  */    
 static void allocate_bytes(private_prf_plus_t *this, size_t length, chunk_t *chunk)
 {
-       chunk->ptr = malloc(length);
-       chunk->len = length;
-       this->public.get_bytes(&(this->public), length, chunk->ptr);
+       if (length)
+       {
+               chunk->ptr = malloc(length);
+               chunk->len = length;
+               get_bytes(this, length, chunk->ptr);
+       }
+       else
+       {
+               *chunk = chunk_empty;
+       }
 }
 
 /**