You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by tv...@aventail.com on 1999/05/17 21:14:43 UTC

problem in http_config.c:ap_handle_command?

In http_config.c:ap_handle_command

[ 1]	else {
[ 2]	    void *mconfig = ap_get_module_config(config, mod);
[ 3]	    void *sconfig =
[ 4]		ap_get_module_config(parms->server->module_config, mod);
[ 5]
[ 6]	    if (!mconfig && mod->create_dir_config) {
[ 7]		mconfig = (*mod->create_dir_config) (parms->pool, parms->path);
[ 8]		ap_set_module_config(config, mod, mconfig);
[ 9]	    }
[10]
[11]	    if (!sconfig && mod->create_server_config) {
[12]		sconfig =
[13]		    (*mod->create_server_config) (parms->pool, parms->server);
[14]		ap_set_module_config(parms->server->module_config, mod, sconfig);
[15]	    }
[16]
[17]	    retval = invoke_cmd(cmd, parms, mconfig, args);
[18]	    mod = mod->next;	/* Next time around, skip this one */
[19]	}

It seems pretty legit that at #2 mconfig could come up NULL. Why, I
dunno. But at any rate, mconfig is created, possibly, at #7. mconfig will
*not* be created if the module in question does not have a per-directory
configuration create hook, see #6.

The problem lies at #17. mconfig is passed to invoke_cmd. But there is the
possiblity that mconfig could be NULL at this point. This module causes a
SIGSEGV because of this.

#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "http_protocol.h"

module MODULE_VAR_EXPORT ass_module;

typedef struct _ass_sconfig_t {
	char *ass_uri;
	char *tmpl_dir;
} ass_sconfig_t;

static void *
server_config_create(pool *p, server_rec *s)
{
    ass_sconfig_t *sconfig;

    sconfig = (ass_sconfig_t *) ap_pcalloc(p, sizeof(ass_sconfig_t));

    sconfig->ass_uri   = "/ass";
    sconfig->tmpl_dir  = ap_server_root_relative(p, "templates/");

    return (void *) sconfig;
}

static const command_rec
ass_commands[] = {
    { "AssURI", ap_set_string_slot,
	  (void *) XtOffsetOf(ass_sconfig_t, ass_uri), RSRC_CONF, TAKE1,
	  "this explains this directive" },
    { "AssTmplDir", ap_set_file_slot,
	  (void *) XtOffsetOf(ass_sconfig_t, tmpl_dir), RSRC_CONF, TAKE1,
	  "this explains this directive" },
    { NULL }
};

module MODULE_VAR_EXPORT ass_module = {
   STANDARD_MODULE_STUFF,
   NULL,                        /* module initializer                  */
   NULL,                        /* create per-dir    config structures */
   NULL,                        /* merge  per-dir    config structures */
   server_config_create,        /* create per-server config structures */
   NULL,                        /* merge  per-server config structures */
   ass_commands,                /* table of config file commands       */
   NULL,                        /* [#8] MIME-typed-dispatched handlers */
   NULL,                        /* [#1] URI to filename translation    */
   NULL,                        /* [#4] validate user id from request  */
   NULL,                        /* [#5] check if the user is ok _here_ */
   NULL,                        /* [#3] check access by host address   */
   NULL,                        /* [#6] determine MIME type            */
   NULL,                        /* [#7] pre-run fixups                 */
   NULL,                        /* [#9] log a transaction              */
   NULL,                        /* [#2] header parser                  */
   NULL,                        /* child_init                          */
   NULL,                        /* child_exit                          */
   NULL                         /* [#0] post read-request              */
};

Here is a backtrace:

(gdb) bt
#0  0x8066604 in ap_set_file_slot (cmd=0xbffffb08, struct_ptr=0x0, arg=0x80a18dc "templates/") at http_config.c:1068
#1  0x8065b44 in invoke_cmd (cmd=0x808f8cc, parms=0xbffffb08, mconfig=0x0, args=0xbfffdaad "") at http_config.c:805
#2  0x8066477 in ap_handle_command (parms=0xbffffb08, config=0x80a10f4, l=0xbfffda98 "AssTmplDir templates/") at http_config.c:1000
#3  0x8066508 in ap_srm_command_loop (parms=0xbffffb08, config=0x80a10f4) at http_config.c:1013
#4  0x8066904 in ap_process_resource_config (s=0x80a059c, fname=0x80a17fc "/users/tvaughan/apache/conf/httpd.conf", p=0x80a0574, ptemp=0x80a2584) at http_config.c:1193
#5  0x80671c2 in ap_read_config (p=0x80a0574, ptemp=0x80a2584, confname=0x809e550 "conf/httpd.conf") at http_config.c:1472
#6  0x8070eae in main (argc=2, argv=0xbffffbc0) at http_main.c:4574

This module is not a DSO. And either:

        AssURI /foobar
        AssTmplDir foobar/

in any order, anywhere (not that I've tried every combination) will cause
this to happen.

So, am I overlooking something obvious? Done something stupid? Or is this a
problem? Why would sconfig not be passed to invoke_cmd?

Apache: 1.3.6
OS: RH 5.2 GNU/Linux
Compiler: egcs

Much Thanks,
Tom

-- 
Tom Vaughan <tvaughan at aventail dot com>

Re: problem in http_config.c:ap_handle_command?

Posted by Rodent of Unusual Size <Ke...@Golux.Com>.
tvaughan@aventail.com wrote:
> 
> The problem lies at #17. mconfig is passed to invoke_cmd. But there is the
> possiblity that mconfig could be NULL at this point. This module causes a
> SIGSEGV because of this.

That's a problem with your module, then.

> So, am I overlooking something obvious? Done something stupid? Or is this a
> problem? Why would sconfig not be passed to invoke_cmd?

The semantics of directive handlers are that they're called
with the per-dir per-module config record if it exists.  Not the
server per-module config record.  If you're going to use the API
routines ap_set_*_slot(), you need to create something that will
be passed to them.  Otherwise you need to write your own handler
that locates your sconfig pointer in the cmd->server->module_config
list (using ap_get_module_config()) and uses that instead.
-- 
#ken    P-)}

Ken Coar                    <http://Web.Golux.Com/coar/>
Apache Software Foundation  <http://www.apache.org/>
"Apache Server for Dummies" <http://Web.Golux.Com/coar/ASFD/>

Re: problem in http_config.c:ap_handle_command?

Posted by Dean Gaudet <dg...@arctic.org>.

On 17 May 1999 tvaughan@aventail.com wrote:

> So, am I overlooking something obvious? Done something stupid? Or is this a
> problem? Why would sconfig not be passed to invoke_cmd?

Search the new-httpd archives... I think ages ago before the release of
1.2 this exact same question came up.

per-server configs and per-dir configs are *not* interchangeable.

Dean