[HACKERS] Multiple false-positive warnings from Valgrind - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject [HACKERS] Multiple false-positive warnings from Valgrind
Date
Msg-id 20170321135742.GB23103@e733.localdomain
Whole thread Raw
Responses Re: [HACKERS] Multiple false-positive warnings from Valgrind  (Michael Paquier <michael.paquier@gmail.com>)
List pgsql-hackers
Hello.

I need a little help.

Recently I've decided to run PostgreSQL under Valgrind according to wiki
description [1]. Lots of warnings are generated [2] but it is my
understanding that all of them are false-positive. For instance I've
found these two reports particularly interesting:

```
==00:00:40:40.161 7677== Use of uninitialised value of size 8
==00:00:40:40.161 7677==    at 0xA15FF5: pg_b64_encode (base64.c:68)
==00:00:40:40.161 7677==    by 0x6FFE85: scram_build_verifier (auth-scram.c:348)
==00:00:40:40.161 7677==    by 0x6F3F76: encrypt_password (crypt.c:171)
==00:00:40:40.161 7677==    by 0x68F40C: CreateRole (user.c:403)
==00:00:40:40.161 7677==    by 0x85D53A: standard_ProcessUtility (utility.c:716)
==00:00:40:40.161 7677==    by 0x85CCC7: ProcessUtility (utility.c:353)
==00:00:40:40.161 7677==    by 0x85BD22: PortalRunUtility (pquery.c:1165)
==00:00:40:40.161 7677==    by 0x85BF20: PortalRunMulti (pquery.c:1308)
==00:00:40:40.161 7677==    by 0x85B4A0: PortalRun (pquery.c:788)
==00:00:40:40.161 7677==    by 0x855672: exec_simple_query (postgres.c:1101)
==00:00:40:40.161 7677==    by 0x8597BB: PostgresMain (postgres.c:4066)
==00:00:40:40.161 7677==    by 0x7C6322: BackendRun (postmaster.c:4317)
==00:00:40:40.161 7677==  Uninitialised value was created by a stack allocation
==00:00:40:40.161 7677==    at 0x6FFDB7: scram_build_verifier (auth-scram.c:328)

==00:00:40:40.593 7677== Use of uninitialised value of size 8
==00:00:40:40.593 7677==    at 0x8A7C36: hex_encode (encode.c:132)
==00:00:40:40.593 7677==    by 0x6FFEF5: scram_build_verifier (auth-scram.c:355)
==00:00:40:40.593 7677==    by 0x6F3F76: encrypt_password (crypt.c:171)
==00:00:40:40.593 7677==    by 0x68F40C: CreateRole (user.c:403)
==00:00:40:40.593 7677==    by 0x85D53A: standard_ProcessUtility (utility.c:716)
==00:00:40:40.593 7677==    by 0x85CCC7: ProcessUtility (utility.c:353)
==00:00:40:40.593 7677==    by 0x85BD22: PortalRunUtility (pquery.c:1165)
==00:00:40:40.593 7677==    by 0x85BF20: PortalRunMulti (pquery.c:1308)
==00:00:40:40.593 7677==    by 0x85B4A0: PortalRun (pquery.c:788)
==00:00:40:40.593 7677==    by 0x855672: exec_simple_query (postgres.c:1101)
==00:00:40:40.593 7677==    by 0x8597BB: PostgresMain (postgres.c:4066)
==00:00:40:40.593 7677==    by 0x7C6322: BackendRun (postmaster.c:4317)
==00:00:40:40.593 7677==  Uninitialised value was created by a stack allocation
==00:00:40:40.593 7677==    at 0x6FFDB7: scram_build_verifier (auth-scram.c:328)
==00:00:40:40.593 7677==
```

And here is what I see in GDB [3]:

```
0x0000000000a160b4 in pg_b64_encode (src=0xffefffb10 [...] at base64.c:80
80          *p++ = _base64[(buf >> 12) & 0x3f];
(gdb) monitor get_vbits 0xffefffb10 10
ffffffff ffffffff ffff

0x00000000008a7c36 in hex_encode (   src=0xffefffbc0 [...] at encode.c:132
132         *dst++ = hextbl[(*src >> 4) & 0xF];
(gdb) monitor get_vbits 0xffefffbc0 32
ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
```

So Valgrind thinks that in both cases first argument is completely
uninitialized which is very doubtful to say the least :) There are also
lots of memory leak reports which could be found in [2].

I got a strong feeling that maybe I'm doing something wrong. Here are
exact script I'm using to build [4], install and run PostgreSQL under
Valgrind [5]. Naturally USE_VALGRIND in declared in pg_config_manual.h.
Valgrind version is 3.12 and an environment in general is Arch Linux.

Could you please give a little piece of advice? Or maybe a wiki page is
just a bit outdated?

[1] https://wiki.postgresql.org/wiki/Valgrind
[2] http://afiskon.ru/s/8a/390698e914_valgrind.tgz
[3] http://afiskon.ru/s/09/c4f6231679_pgvg.txt
[4] https://github.com/afiskon/pgscripts/blob/master/quick-build.sh
[5] https://github.com/afiskon/pgscripts/blob/master/valgrind.sh

--
Best regards,
Aleksander Alekseev

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] Freeze on Cygwin w/ concurrency
Next
From: Amit Kapila
Date:
Subject: Re: [HACKERS] Patch: Write Amplification Reduction Method (WARM)