diff options
author | Bruce Momjian <bruce@momjian.us> | 2014-04-17 12:37:53 -0400 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2014-04-17 12:37:53 -0400 |
commit | fc72e94a13026b86a06c7f5c670f4c16420d3d77 (patch) | |
tree | 0572054c47891b08d2e47a3223a09eea87f2b46c /contrib/pgcrypto/pgp-decrypt.c | |
parent | 071d9f085089f3fbae1b472debd38c555cd4a436 (diff) | |
download | postgresql-fc72e94a13026b86a06c7f5c670f4c16420d3d77.tar.gz postgresql-fc72e94a13026b86a06c7f5c670f4c16420d3d77.zip |
pgcrypto: fix memset() calls that might be optimized away
Specifically, on-stack memset() might be removed, so:
* Replace memset() with px_memset()
* Add px_memset to copy_crlf()
* Add px_memset to pgp-s2k.c
Patch by Marko Kreen
Report by PVS-Studio
Backpatch through 8.4.
Diffstat (limited to 'contrib/pgcrypto/pgp-decrypt.c')
-rw-r--r-- | contrib/pgcrypto/pgp-decrypt.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/contrib/pgcrypto/pgp-decrypt.c b/contrib/pgcrypto/pgp-decrypt.c index c9aa6cd66aa..2063e8c319e 100644 --- a/contrib/pgcrypto/pgp-decrypt.c +++ b/contrib/pgcrypto/pgp-decrypt.c @@ -210,7 +210,7 @@ pktreader_free(void *priv) { struct PktData *pkt = priv; - memset(pkt, 0, sizeof(*pkt)); + px_memset(pkt, 0, sizeof(*pkt)); px_free(pkt); } @@ -257,7 +257,7 @@ prefix_init(void **priv_p, void *arg, PullFilter *src) if (res != len + 2) { px_debug("prefix_init: short read"); - memset(tmpbuf, 0, sizeof(tmpbuf)); + px_memset(tmpbuf, 0, sizeof(tmpbuf)); return PXE_PGP_CORRUPT_DATA; } @@ -280,7 +280,7 @@ prefix_init(void **priv_p, void *arg, PullFilter *src) */ ctx->corrupt_prefix = 1; } - memset(tmpbuf, 0, sizeof(tmpbuf)); + px_memset(tmpbuf, 0, sizeof(tmpbuf)); return 0; } @@ -395,8 +395,8 @@ mdc_finish(PGP_Context *ctx, PullFilter *src, */ px_md_finish(ctx->mdc_ctx, hash); res = memcmp(hash, *data_p, 20); - memset(hash, 0, 20); - memset(tmpbuf, 0, sizeof(tmpbuf)); + px_memset(hash, 0, 20); + px_memset(tmpbuf, 0, sizeof(tmpbuf)); if (res != 0) { px_debug("mdc_finish: mdc failed"); @@ -493,7 +493,7 @@ mdcbuf_finish(struct MDCBufData * st) px_md_update(st->ctx->mdc_ctx, st->mdc_buf, 2); px_md_finish(st->ctx->mdc_ctx, hash); res = memcmp(hash, st->mdc_buf + 2, 20); - memset(hash, 0, 20); + px_memset(hash, 0, 20); if (res) { px_debug("mdcbuf_finish: MDC does not match"); @@ -593,7 +593,7 @@ mdcbuf_free(void *priv) px_md_free(st->ctx->mdc_ctx); st->ctx->mdc_ctx = NULL; - memset(st, 0, sizeof(*st)); + px_memset(st, 0, sizeof(*st)); px_free(st); } @@ -703,7 +703,7 @@ parse_symenc_sesskey(PGP_Context *ctx, PullFilter *src) res = decrypt_key(ctx, p, res); } - memset(tmpbuf, 0, sizeof(tmpbuf)); + px_memset(tmpbuf, 0, sizeof(tmpbuf)); return res; } @@ -753,6 +753,7 @@ copy_crlf(MBuf *dst, uint8 *data, int len, int *got_cr) if (res < 0) return res; } + px_memset(tmpbuf, 0, sizeof(tmpbuf)); return 0; } @@ -792,7 +793,7 @@ parse_literal_data(PGP_Context *ctx, MBuf *dst, PullFilter *pkt) px_debug("parse_literal_data: unexpected eof"); return PXE_PGP_CORRUPT_DATA; } - memset(tmpbuf, 0, 4); + px_memset(tmpbuf, 0, 4); /* check if text */ if (ctx->text_mode) |