Skip to content

refcount crash in binmode() if inappropriate LAYERs passed #20915

Open
@jimav

Description

@jimav

binmode() causes a refcount crash if the :unix LAYER is passed and the file descriptor refers to an in-memory file:

#!/usr/bin/env perl
my $buffer = "";
open(my $fh, ">", \$buffer) or die "open to buffer: $!";
binmode($fh);
binmode($fh, ':unix:utf8');   #  **dies**    refcnt_inc: fd -1 < 0

Certainly not a show-stopper, of course. Just wondering if this could be properly caught and die with a user-oriented message such as "The ':unix' layer is inapplicable to this kind of file".

Or, fail with EINVAL possibly with a warning (assuming it is safe to return from the point of detection). A forced fatal would be okay IMO.

Perl configuration

Summary of my perl5 (revision 5 version 36 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=5.19.0-29-generic
    archname=x86_64-linux
    uname='linux test-virtualbox 5.19.0-29-generic #30-ubuntu smp preempt_dynamic wed jan 4 12:14:09 utc 2023 x86_64 x86_64 x86_64 gnulinux '
    config_args='-de -Dprefix=/home/brew/perl5/perlbrew/perls/perl-5.36.0 -Aeval:scriptdir=/home/brew/perl5/perlbrew/perls/perl-5.36.0/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='12.2.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /usr/lib64
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/x86_64-linux-gnu/libc.so.6
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.36'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under linux
  Compiled at Jan 21 2023 00:30:33
  %ENV:
    PERL5LIB="/home/brew/src/Tie-Indirect/lib:/home/brew/src/Spreadsheet-Edit/lib:/home/brew/src/Data-Dumper-Interp/lib"
    PERLBREW_HOME="/home/brew/.perlbrew"
    PERLBREW_MANPATH="/home/brew/perl5/perlbrew/perls/perl-5.36.0/man"
    PERLBREW_PATH="/home/brew/perl5/perlbrew/bin:/home/brew/perl5/perlbrew/perls/perl-5.36.0/bin"
    PERLBREW_PERL="perl-5.36.0"
    PERLBREW_ROOT="/home/brew/perl5/perlbrew"
    PERLBREW_SHELLRC_VERSION="0.96"
    PERLBREW_VERSION="0.96"
  @INC:
    /home/brew/src/Tie-Indirect/lib
    /home/brew/src/Spreadsheet-Edit/lib
    /home/brew/src/Data-Dumper-Interp/lib
    /home/brew/perl5/perlbrew/perls/perl-5.36.0/lib/site_perl/5.36.0/x86_64-linux
    /home/brew/perl5/perlbrew/perls/perl-5.36.0/lib/site_perl/5.36.0
    /home/brew/perl5/perlbrew/perls/perl-5.36.0/lib/5.36.0/x86_64-linux
    /home/brew/perl5/perlbrew/perls/perl-5.36.0/lib/5.36.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions