Skip to content

Commit 59b9198

Browse files
committed
Prevent Valgrind Memcheck errors around px_acquire_system_randomness().
This function uses uninitialized stack and heap buffers as supplementary entropy sources. Mark them so Memcheck will not complain. Back-patch to 9.4, where Valgrind Memcheck cooperation first appeared. Marko Tiikkaja
1 parent 8b59672 commit 59b9198

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

contrib/pgcrypto/random.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "postgres.h"
3333

3434
#include "px.h"
35+
#include "utils/memdebug.h"
3536

3637
/* how many bytes to ask from system random provider */
3738
#define RND_BYTES 32
@@ -195,16 +196,18 @@ try_unix_std(uint8 *dst)
195196
memcpy(dst, (uint8 *) &x, sizeof(x));
196197
dst += sizeof(x);
197198

198-
/* let's be desperate */
199+
/* hash of uninitialized stack and heap allocations */
199200
res = px_find_digest("sha1", &md);
200201
if (res >= 0)
201202
{
202203
uint8 *ptr;
203204
uint8 stack[8192];
204205
int alloc = 32 * 1024;
205206

207+
VALGRIND_MAKE_MEM_DEFINED(stack, sizeof(stack));
206208
px_md_update(md, stack, sizeof(stack));
207209
ptr = px_alloc(alloc);
210+
VALGRIND_MAKE_MEM_DEFINED(ptr, alloc);
208211
px_md_update(md, ptr, alloc);
209212
px_free(ptr);
210213

0 commit comments

Comments
 (0)