Browse Source

Prevent undefined behavior

Don't call XMEMCPY() in case info (the source parameter to memcpy) is NULL
as this would trigger UB
Steffen Jaeckel 10 years ago
parent
commit
f5016d88dd
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/misc/hkdf/hkdf.c

+ 3 - 1
src/misc/hkdf/hkdf.c

@@ -61,7 +61,9 @@ int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
    if (T == NULL) {
    if (T == NULL) {
       return CRYPT_MEM;
       return CRYPT_MEM;
    }
    }
-   XMEMCPY(T + hashsize, info, infolen);
+   if (info != NULL) {
+      XMEMCPY(T + hashsize, info, infolen);
+   }
 
 
    /* HMAC data T(1) doesn't include a previous hash value */
    /* HMAC data T(1) doesn't include a previous hash value */
    dat    = T    + hashsize;
    dat    = T    + hashsize;