Skip to content

Commit

Permalink
Fix potential memory leak and handle zero-length allocation, CID 379854
Browse files Browse the repository at this point in the history
  • Loading branch information
olszomal committed Feb 13, 2025
1 parent 557a9e4 commit 3710835
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/p11_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,16 @@ void pkcs11_addattr_obj(PKCS11_TEMPLATE *tmpl, int type, pkcs11_i2d_fn enc, void
size_t n;

n = enc(obj, NULL);
if (n == 0)
return;

buf = p = OPENSSL_malloc(n);
if (n && p) {
enc(obj, &p);
i = pkcs11_addattr(tmpl, type, buf, n);
tmpl->allocated |= 1<<i;
}
if (!buf)
return;

enc(obj, &p);
i = pkcs11_addattr(tmpl, type, buf, n);
tmpl->allocated |= 1<<i;
}

void pkcs11_zap_attrs(PKCS11_TEMPLATE *tmpl)
Expand Down

0 comments on commit 3710835

Please sign in to comment.