Re: Segfault on ppc-linux with modperl-1.25 with Apache 1.3.19 whencalling $r-send_fd()

2001-06-13 Thread Doug MacEachern

On 19 Mar 2001, Mark Lipscombe wrote:


   open ($FH, $fname);
...
   $r-send_fd($FH);

you didn't check the return value of open();  patch below will check if
the filehandle is NULL and croak rather than segfault.

Index: src/modules/perl/Apache.xs
===
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.122
diff -u -r1.122 Apache.xs
--- src/modules/perl/Apache.xs  2001/06/14 04:36:21 1.122
+++ src/modules/perl/Apache.xs  2001/06/14 05:24:25
@@ -956,6 +956,10 @@
 long length
 
 CODE:
+if (!f) {
+croak(send_fd: NULL filehandle 
+  (hint: did you check the return value of open?));
+}
 RETVAL = send_fd_length(f, r, length);
 
 OUTPUT:




Segfault on ppc-linux with modperl-1.25 with Apache 1.3.19 whencalling $r-send_fd()

2001-03-18 Thread Mark Lipscombe

Hi,

Apologies in advance for the length of this message.

I have two (apparently) identical setups, consisting of the following:

Apache 1.3.19 with php4, mod_ssl  mod_perl compiled statically
Perl 5.6.0 (output of -V appears at the end of this message)

The only obvious difference is system A is i386-linux, and system B is
powerpc-linux.

Everything is fine on the i386 system, but this script on the PowerPC
causes a segfault without fail:

package Apache::LogoMikvas;

use strict;
use DBI ();
use File::Temp qw/ :POSIX /;
use vars qw($DBH);
use constant DBAUTH = 'root:fr3dcak3';
use constant MAX_TRIES  = 10;

use Apache::Constants qw(:common);

sub handler {
my $r = shift;
my $DB = 'dbi:mysql:'.$ENV{DATABASE};

my %args = $r-args;
my ($www, $username, $domain) = split('\.', $r-header_in('Host'),
3); 

unless ($username =~ /(\w+)/) {
Apache::LogoMikvas::FAILED("Non-sane input for /img/logo.gif:
$username");
}
my $DBH = DBI-connect($DB, split(':', DBAUTH, 2), {PrintError =
0})
|| Apache::LogoMikvas::FAILED($DBI::errstr);

my $find_logo = $DBH-prepare(END) ||
Apache::LogoMikvas::FAILED($DBI::errstr);
SELECT sites.sites_logo, date_format(sites_last_modified, '%W, %d %M %Y
%H:%i:%s') AS lms,
users.users_id
FROM users, sites
WHERE sites.sites_users_id = users.users_id
AND users.users_username = ?
END

$find_logo-execute($username) ||
Apache::LogoMikvas::FAILED($DBI::errstr);
my $find_logo_data = $find_logo-fetchrow_hashref ||
Apache::LogoMikvas::FAILED($DBI::errstr);
$find_logo-finish;

$r-no_cache(1);
$r-content_type('image/gif');
$r-send_http_header;
if ($find_logo_data-{sites_logo}) {
  my ($FH, $fname);
  $fname = $ENV{IMAGE_PATH} . $find_logo_data-{sites_logo};
  open ($FH, $fname);
  #$r-print("Filename we're trying to read: $fname\n");
  $r-send_fd($FH);
  #$r-print($find_logo_data-{sites_logo});
} else {
  
$r-printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%",
 
71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
}

return OK;
}

sub FAILED {
my $errstr = shift;
die($errstr);
Apache::exit();
}

1;


The segfault occurs when $r-send_fd is called, the following is a stack
trace from running httpd -X and
requesting the URL in question:

Program received signal SIGSEGV, Segmentation fault.
0x1622664 in _IO_sgetn () at genops.c:365
365 genops.c: No such file or directory.
(gdb) bt
#0  0x1622664 in _IO_sgetn () at genops.c:365
#1  0x161cb38 in fread () at iofread.c:46
#2  0x188a71c in ap_send_fd_length ()
#3  0x1858530 in XS_Apache_send_fd ()
#4  0x193f694 in Perl_pp_entersub ()
#5  0x19386c4 in Perl_runops_standard ()
#6  0x18ee0d4 in S_call_body ()
#7  0x18edde4 in perl_call_sv ()
#8  0x184bfac in perl_call_handler ()
#9  0x184b7b4 in perl_run_stacked_handlers ()
#10 0x1849bb4 in perl_handler ()
#11 0x18731b0 in ap_invoke_handler ()
#12 0x188f09c in process_request_internal ()
#13 0x188f12c in ap_process_request ()
#14 0x1883adc in child_main ()
#15 0x1883cfc in make_child ()
#16 0x1883ed4 in startup_children ()
#17 0x1884754 in standalone_main ()
#18 0x18850bc in main ()
#19 0x15eb77c in __libc_start_main ()
at ../sysdeps/powerpc/elf/libc-start.c:107
#20 0x0 in ?? ()

If comment out the send_fd, it works fine.

Here is the output of perl -V:

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
osname=linux, osvers=2.4.3-pre4, archname=ppc-linux
uname='linux devbox 2.4.3-pre4 #1 thu mar 15 16:44:38 est 2001 ppc
unknown 'config_args=''
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=define 
use64bitint=undef use64bitall=undef uselongdouble=undef
usesocks=undef
  Compiler:
cc='gcc', optimize='-O2', gccversion=2.95.2 19991024 (release)
cppflags='-fno-strict-aliasing -I/usr/local/include'
ccflags ='-fno-strict-aliasing -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
stdchar='char', d_stdstdio=define, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
ld='gcc', ldflags =''
libpth=/lib /usr/lib
libs=-lnsl -lndbm -lgdbm -ldbm -ldl -lm -lc -lposix -lcrypt
libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared'


Characteristics of this binary (from libperl): 
  Compile-time options: USE_LARGE_FILES
  Built under linux
  Compiled at Mar 17 2001 14:19:00
  @INC: