mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
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.
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user