apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject OS/2 apr_file_open truncation bug
Date Fri, 03 Jun 2005 13:58:18 GMT
I was reminded by someone recently that mod_dav is broken on OS/2 in 2.0
because of this bug.  Brian, can you have a look?

----- Forwarded message from bugzilla@apache.org -----

From: bugzilla@apache.org
Reply-To: "Apache HTTPD Bugs Notification List" <bugs@httpd.apache.org>
To: bugs@httpd.apache.org
Date: Fri, 4 Mar 2005 14:34:30 +0100
Subject: New: #33844: 
    PUT with Content-Range destroys file content


http://issues.apache.org/bugzilla/show_bug.cgi?id=33844

           Summary: PUT with Content-Range destroys file content
           Product: Apache httpd-2.0
           Version: 2.1-HEAD
          Platform: PC
        OS/Version: OS/2
            Status: NEW
          Severity: normal
          Priority: P2
         Component: mod_dav
        AssignedTo: bugs@httpd.apache.org
        ReportedBy: sunlover@anduin.net


Actually bug is in APR:
/apr/branches/1.1.x/file_io/os2/open.c

Problem is that when a PUT is made with Content_Range: to a existing DAV
resource, the file is truncated.

Here are explanation why this happen and how to fix it:

DAV module (dav_fs_open_stream called with DAV_MODE_WRITE_SEEKABLE)
calls APR without the APR_TRUNCATE flag:
    switch (mode) {
    default:
        flags = APR_READ | APR_BINARY;
        break;

    case DAV_MODE_WRITE_TRUNC:
        flags = APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BINARY;
        break;
    case DAV_MODE_WRITE_SEEKABLE:
        flags = APR_WRITE | APR_CREATE | APR_BINARY;
        break;
    }

but APR sets OPEN_ACTION_REPLACE_IF_EXISTS for the given APR flags:
    if (flag & APR_CREATE) {
        oflags |= OPEN_ACTION_CREATE_IF_NEW;
        if (!(flag & APR_EXCL)) {
            if (flag & APR_APPEND)
                oflags |= OPEN_ACTION_OPEN_IF_EXISTS;
            else
                oflags |= OPEN_ACTION_REPLACE_IF_EXISTS;
        }
    }

So the fix is to remove 'if (flag & APR_APPEND)' statement:
    if (flag & APR_CREATE) {
        oflags |= OPEN_ACTION_CREATE_IF_NEW;
        if (!(flag & APR_EXCL)) {
            oflags |= OPEN_ACTION_OPEN_IF_EXISTS;
        }
    }


Note that the OPEN_ACTION_REPLACE_IF_EXISTS is explicitly set later
in the function if APR_TRUNCATE is specified.

I checked Win32 code and file is not truncated there if
APR_WRITE | APR_CREATE | APR_BINARY flags are set.
Which is a right behaviour.

----- End forwarded message -----

Mime
View raw message