During my analysis of PR39643 
(http://issues.apache.org/bugzilla/show_bug.cgi?id=39643)
I found out that mod_cache and mod_filter do not work together correctly. In 
fact mod_filter
crashes with a segfault if the content is delivered from the cache.

The segfault is caused by line 366 of mod_filter (filter_harness):

 if (!ctx->func) {

filter_harness implements the output filter of mod_filter.
It expects that its context has been initialized and does not perform a check 
if this is true.

Why is the context not initialized, if we deliver content from the cache?

This is because the filters (and thus the contexts of at least some filters) 
get initialized
in ap_invoke_filter_init which is a static function in config.c. 
ap_invoke_filter_init gets
only called by ap_invoke_handler (also in config.c). But if we deliver content 
from the cache we
do this inside the quick handler hook, which is run *before* ap_invoke_handler. 
Although we call
ap_run_insert_filter in the mod_cache quick handler we do *not* initialize the 
filters there.

So basicly I see the following approach for a fix:

1. In mod_filter do a sanity check if the filter context has been initialized. 
If not remove ourselves
   from the chain and simply pass the brigade. This could be done by the 
following simple patch:

--- mod_filter.c        (Revision 408729)
+++ mod_filter.c        (Arbeitskopie)
@@ -355,7 +355,7 @@
     harness_ctx *ctx = f->ctx;
     ap_filter_rec_t *filter = f->frec;

-    if (f->r->status != 200) {
+    if ((!ctx) || (f->r->status != 200)) {
         ap_remove_output_filter(f);
         return ap_pass_brigade(f->next, bb);
     }

   Or does somebody sees a need for an error message here if the context is not 
initialized?

2. Convert ap_invoke_filter_init from a static function to a public function 
that is part of the API
   and let mod_cache call it after ap_run_insert_filter.
   Questions:

   1. What kind of DECLARE macro should be used to convert it to a public 
function ?
   2. To which header file should we add the prototype?
   3. Any special steps needed to adjust exports.c or is this done 
automatically during
      make / configure?
   4. Does this require a minor bump (I assume yes)?

Comments / Thoughts / Answers ?


Regards

RĂ¼diger

Reply via email to