You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dean Gaudet <dg...@arctic.org> on 1998/01/27 04:07:11 UTC

problem with the table_xxxn API and mod_include

mod_include plays a questionable game with r->subprocess_env.  It
originally had code like this:

    if (r->main) {
        /* Kludge --- for nested includes, we want to keep the
         * subprocess environment of the base document (for compatibility);
         * that means torquing our own last_modified date as well so that
         * the LAST_MODIFIED variable gets reset to the proper value if
         * the nested document resets <!--#config timefmt-->
         */
        r->subprocess_env = r->main->subprocess_env;
        r->finfo.st_mtime = r->main->finfo.st_mtime;
    }
    else {
        add_common_vars(r);
        add_cgi_vars(r);
        add_include_vars(r, DEFAULT_TIME_FORMAT);
    }

The problem with this is that with the table_xxxn API change it's
completely bogus to make that assignment to r->subprocess_env.
In particular it's definately likely that a value will be placed into
the table which is allocated from the wrong pool.  (The wrong pool being
r->pool rather than r->main->pool.)

This can cause memory corruption... and certainly trips all over POOL_DEBUG
if you've got it enabled.  I've checked in a workaround that at least
gets rid of the corruption and abort() :

    if (r->main) {
        /* Kludge --- for nested includes, we want to keep the subprocess
         * environment of the base document (for compatibility).  This is only
         * necessary when there has been an internal redirect somewhere along
         * the way.  When that happens the original environment has been
         * renamed REDIRECT_foobar for each foobar.
         */
        r->subprocess_env = copy_table(r->pool, r->main->subprocess_env);
    }
    else {
        add_common_vars(r);
        add_cgi_vars(r);
        add_include_vars(r, DEFAULT_TIME_FORMAT);
    }

But... there's a problem.  This breaks <!--#set --> used inside a
<!--#include --> file.  The change happens, but the result isn't
propagated to the main request, and so appears as if it didn't happen
in the parent document.

I'm not sure how to fix this yet.  Ideas welcome.  I've one idea --
a new function, table_pool(t) which returns the pool for table t.  Then
methodically go around and ensure that allocations are done correctly.
The impact is zero on code speed, but makes it correct (and then
I can revert this change to mod_include).

Dean