Show
Ignore:
Timestamp:
03/09/08 03:58:16 (21 months ago)
Author:
bradfitz
Message:

SECURITY: patch from Jeremey James <jbj@…> to not crash
on zero byte chunked upload when buffered uploads are enabled.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Perlbal/ClientProxy.pm

    r763 r766  
    10211021    # reset our position so we start reading from the right spot 
    10221022    $self->{buoutpos} = 0; 
    1023     sysseek($self->{bufh}, 0, 0); 
     1023    sysseek($self->{bufh}, 0, 0) if ($self->{bufh}); # But only if it exists at all 
    10241024 
    10251025    # notify that we want the backend so we get the ball rolling 
     
    10351035    my $clen = $self->{request_body_length}; 
    10361036 
    1037     my $sent = Perlbal::Socket::sendfile($be->{fd}, fileno($self->{bufh}), $clen - $self->{buoutpos}); 
    1038     if ($sent < 0) { 
    1039         return $self->close("epipe") if $! == EPIPE; 
    1040         return $self->close("connreset") if $! == ECONNRESET; 
    1041         print STDERR "Error w/ sendfile: $!\n"; 
    1042         return $self->close('sendfile_error'); 
    1043     } 
    1044     $self->{buoutpos} += $sent; 
     1037    if ($self->{buoutpos} < $clen) { 
     1038        my $sent = Perlbal::Socket::sendfile($be->{fd}, fileno($self->{bufh}), $clen - $self->{buoutpos}); 
     1039        if ($sent < 0) { 
     1040            return $self->close("epipe") if $! == EPIPE; 
     1041            return $self->close("connreset") if $! == ECONNRESET; 
     1042            print STDERR "Error w/ sendfile: $!\n"; 
     1043            return $self->close('sendfile_error'); 
     1044        } 
     1045        $self->{buoutpos} += $sent; 
     1046    } 
    10451047 
    10461048    # if we're done, purge the file and move on 
     
    11551157sub purge_buffered_upload { 
    11561158    my Perlbal::ClientProxy $self = shift; 
     1159 
     1160    # Main reason for failure below is a 0-length chunked upload, where the file is never created. 
     1161    return unless $self->{bufh}; 
    11571162 
    11581163    # FIXME: it's reported that sometimes the two now-in-eval blocks