pmqs / DB_File

DB_File - Perl5 access to Berkeley DB version 1.x
8 stars 3 forks source link

ParseOpenInfo() leaks if it croaks #1

Closed iabyn closed 5 years ago

iabyn commented 5 years ago

ParseOpenInfo() initially mallocs a DB_File_type buf. If it then croaks for any reason, this buffer leaks. This shows up in bleadperl as failing tests under clang's Address Sanitizer. A sample failure script (reduced from db-btree.t) is

use DB_File; 
my $filename = "xyz";
my @x;
eval { tie @x, 'DB_File', $filename, 0x42, 0640, $DB_BTREE } ;
unlink $filename;
pmqs commented 5 years ago

Thanks @iabyn - think I see where the problem is.

Need to build a Perl with address sanatizer to reproduce first.

pmqs commented 5 years ago

@iabyn do you have a list of the sanitizer options used when building your perl binary?

Could you post the output from running perl -V please? Think that would show them.

iabyn commented 5 years ago

On Wed, Apr 17, 2019 at 02:55:16PM -0700, Paul Marquess wrote:

@iabyn do you have a list of the sanitizer options used when building your perl binary?

Could you post the output from running perl -V please? Think that would show them.

sh Configure -des -Dusedevel -Dprefix=/home/davem/perl5/git/bleed.out -Uinstallusrbinperl -Duseithreads -Doptimize='-g' -Accflags='-DDEBUGGING -ggdb -fsanitize=address' -Aldflags='-fsanitize=address' -Dcc=clang

when running the tests, you need to set these env vars:

PERL_DESTRUCT_LEVEL=2

to avoid lots of false positives, and possibly

ASAN_OPTIONS=detect_leaks=1

if leak detection isn't enabled by default for that clang.

-- Any [programming] language that doesn't occasionally surprise the novice will pay for it by continually surprising the expert. -- Larry Wall

pmqs commented 5 years ago

Thanks @iabyn, will give that a go

pmqs commented 5 years ago

Reproduced the issue

Direct leak of 136 byte(s) in 1 object(s) allocated from:
    #0 0x4f47d0 in malloc ??:?
    #1 0x4f47d0 in ?? ??:0
    #2 0xafeda0 in Perl_safesysmalloc /home/paul/base/zip/perl/perl-5.28.1/util.c:153
    #3 0xafeda0 in ?? ??:0
    #4 0x7fb56bddc713 in ParseOpenInfo /home/paul/perl/ext/DB_File/DB_File.xs:1276
    #5 0x7fb56bddc713 in ?? ??:0
    #6 0x7fb56bd87857 in XS_DB_File_DoTie_ /home/paul/perl/ext/DB_File/DB_File.xs:1585
    #7 0x7fb56bd87857 in ?? ??:0
    ...
pmqs commented 5 years ago

Issue fixed in change de98123c5d272f5da7d2cfc433276fb9fe8efd7b. Closing issue.