提交 519a5d1e 编写于 作者: G Greg Zaverucha 提交者: Richard Levitte

Fix sample code

Fix memory leak in sample encryption code and check return value of
fopen.

CLA: trivial
Signed-off-by: NGreg Zaverucha <gregz@microsoft.com>
Reviewed-by: NPaul Dale <paul.dale@oracle.com>
Reviewed-by: NRichard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3790)
上级 afe9bba7
...@@ -552,6 +552,7 @@ Encrypt a string using IDEA: ...@@ -552,6 +552,7 @@ Encrypt a string using IDEA:
if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, intext, strlen(intext))) { if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, intext, strlen(intext))) {
/* Error */ /* Error */
EVP_CIPHER_CTX_free(ctx);
return 0; return 0;
} }
/* /*
...@@ -560,6 +561,7 @@ Encrypt a string using IDEA: ...@@ -560,6 +561,7 @@ Encrypt a string using IDEA:
*/ */
if (!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen)) { if (!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen)) {
/* Error */ /* Error */
EVP_CIPHER_CTX_free(ctx);
return 0; return 0;
} }
outlen += tmplen; outlen += tmplen;
...@@ -571,6 +573,10 @@ Encrypt a string using IDEA: ...@@ -571,6 +573,10 @@ Encrypt a string using IDEA:
* NULs. * NULs.
*/ */
out = fopen(outfile, "wb"); out = fopen(outfile, "wb");
if (out == NULL) {
/* Error */
return 0;
}
fwrite(outbuf, 1, outlen, out); fwrite(outbuf, 1, outlen, out);
fclose(out); fclose(out);
return 1; return 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册