You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@apr.apache.org by bu...@apache.org on 2015/04/30 16:20:05 UTC

[Bug 57877] New: Adding a buffer using apr_file_buffer_set() leaves an unbuffered file w/o the required mutex

https://bz.apache.org/bugzilla/show_bug.cgi?id=57877

            Bug ID: 57877
           Summary: Adding a buffer using apr_file_buffer_set() leaves an
                    unbuffered file w/o the required mutex
           Product: APR
           Version: 1.5.1
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: APR
          Assignee: bugs@apr.apache.org
          Reporter: ernstthal@icloud.com

Created attachment 32705
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=32705&action=edit
Patch to apr_file_open() & apr_os_file_put() to always associate a mutex

The default case is to open a file unbuffered, and such a file won't get a
mutex as it is only required for protecting access to the buffer (aside from
the APR_FOPEN_APPEND option). apr_file_buffer_set() can be used to assign a
buffer afterwards, but no mutex will be allocated.

Moreover the implementation for Windows in apr-1.5.1/file_io/win32/buffer.c
tries to apr_thread_mutex_lock() with a NULL mutex in this case, causing
logresolve.exe from httpd-2.4.x to always fail.

The implementation for UNIX of apr_file_buffer_set() (in
apr-1.5.1/file_io/unix/buffer.c) differs by applying the file_lock() & -unlock
macros from apr-1.5.1/include/arch/unix/apr_arch_file_io.h which in turn will
only call apr_thread_mutex_lock() & -unlock if the mutex exists.

My first idea was to create the mutex on demand as shown in the following
patch:
============================================================================
--- apr/file_io/win32/buffer-old.c    2006-08-03 12:55:31.000000000 +0200
+++ apr/file_io/win32/buffer.c    2015-04-28 17:03:02.919790000 +0200
@@ -23,6 +23,14 @@
 {
     apr_status_t rv;

+    if (!file->mutex) {
+        rv = apr_thread_mutex_create(&file->mutex,
+                                     APR_THREAD_MUTEX_DEFAULT, file->pool);
+        if (rv) {
+            return rv;
+        }
+    }
+
     apr_thread_mutex_lock(file->mutex);

     if(file->buffered) {
============================================================================
but creating a new mutex for an opened file would have to be protected by a
mutex on its own. The only save option is to create the mutex right on every
open, even if it won't be used later on (at least #if APR_HAS_THREADS).

Attached is a patch for apr-1.5.1/file_io/win32/open.c with small changes
inside apr_file_open() & apr_os_file_put() commenting out the if statements.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


[Bug 57877] Adding a buffer using apr_file_buffer_set() leaves an unbuffered file w/o the required mutex

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57877

--- Comment #3 from William A. Rowe Jr. <wr...@apache.org> ---
The windows-specific defect is fully addressed in 1.6.5.

The question of creating a mutex remains open. In the meanwhile, 2.0.0
introduces
unmutexed buffered files (optimization for single-actors) so it is not at all
clear
whether this should be a default behavior or not.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


[Bug 57877] Adding a buffer using apr_file_buffer_set() leaves an unbuffered file w/o the required mutex

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57877

--- Comment #1 from ernstthal@icloud.com ---
Also see https://bz.apache.org/bugzilla/show_bug.cgi?id=57876

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


[Bug 57877] Adding a buffer using apr_file_buffer_set() leaves an unbuffered file w/o the required mutex

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57877

--- Comment #2 from Mladen Turk <mt...@apache.org> ---
Trunk patches r1808457 and r1829962 should solve the crash for httpd's
logresolve util which happens because uninitialized mutex is used on
stdout/stderr files.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org