You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Joe Orton <jo...@redhat.com> on 2005/06/03 15:58:18 UTC
OS/2 apr_file_open truncation bug
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" <bu...@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 -----
Re: OS/2 apr_file_open truncation bug
Posted by Brian Havard <br...@kheldar.apana.org.au>.
On Fri, 3 Jun 2005 14:58:18 +0100, Joe Orton wrote:
>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?
I actually encountered the same problem, and another one, when porting
subversion. I'll commit my fixes. I guess I'll have to backport all the way
back to 0.9 to get it into httpd 2.0...
--
______________________________________________________________________________
| Brian Havard | "He is not the messiah! |
| brianh@kheldar.apana.org.au | He's a very naughty boy!" - Life of Brian |
------------------------------------------------------------------------------