]> granicus.if.org Git - postgresql/commitdiff
Prevent Valgrind Memcheck errors around px_acquire_system_randomness().
authorNoah Misch <noah@leadboat.com>
Mon, 2 Feb 2015 15:00:45 +0000 (10:00 -0500)
committerNoah Misch <noah@leadboat.com>
Mon, 2 Feb 2015 15:00:49 +0000 (10:00 -0500)
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

contrib/pgcrypto/random.c

index 3f092ca3461149c73cc772e44bc8c42b017f185e..d72679e412d405dd7cdb136c5be0d6ef203f10a7 100644 (file)
@@ -32,6 +32,7 @@
 #include "postgres.h"
 
 #include "px.h"
+#include "utils/memdebug.h"
 
 /* how many bytes to ask from system random provider */
 #define RND_BYTES  32
@@ -195,7 +196,7 @@ try_unix_std(uint8 *dst)
        memcpy(dst, (uint8 *) &x, sizeof(x));
        dst += sizeof(x);
 
-       /* let's be desperate */
+       /* hash of uninitialized stack and heap allocations */
        res = px_find_digest("sha1", &md);
        if (res >= 0)
        {
@@ -203,8 +204,10 @@ try_unix_std(uint8 *dst)
                uint8           stack[8192];
                int                     alloc = 32 * 1024;
 
+               VALGRIND_MAKE_MEM_DEFINED(stack, sizeof(stack));
                px_md_update(md, stack, sizeof(stack));
                ptr = px_alloc(alloc);
+               VALGRIND_MAKE_MEM_DEFINED(ptr, alloc);
                px_md_update(md, ptr, alloc);
                px_free(ptr);