Simplify parameter checks since this is only called from one place.
Found by Coverity, CID 183502.
ok beck@
-/* $OpenBSD: pvkfmt.c,v 1.19 2017/05/02 03:59:44 deraadt Exp $ */
+/* $OpenBSD: pvkfmt.c,v 1.20 2018/08/05 11:19:25 bcook Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2005.
*/
if (pklen < 0)
return -1;
outlen += pklen;
- if (!out)
- return outlen;
- if (*out)
- p = *out;
- else {
- p = malloc(outlen);
- if (!p) {
- PEMerror(ERR_R_MALLOC_FAILURE);
- return -1;
- }
- *out = p;
+ p = malloc(outlen);
+ if (!p) {
+ PEMerror(ERR_R_MALLOC_FAILURE);
+ return -1;
}
write_ledword(&p, MS_PVKMAGIC);
p += PVK_SALTLEN;
}
do_i2b(&p, pk, 0);
- if (enclevel == 0)
+ if (enclevel == 0) {
+ *out = p;
return outlen;
- else {
+ } else {
char psbuf[PEM_BUFSIZE];
unsigned char keybuf[20];
int enctmplen, inlen;
goto error;
}
EVP_CIPHER_CTX_cleanup(&cctx);
+ *out = p;
return outlen;
error:
EVP_CIPHER_CTX_cleanup(&cctx);
+ free(p);
return -1;
}