Skip to content

Commit ca84dfa

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 258e294 commit ca84dfa

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy