You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Allasso Travesser <al...@gmail.com> on 2013/12/08 05:17:38 UTC

[users@httpd] Seg fault when assigning value in AP_INIT_TAKE1 callback

Hello,

Learning to create modules, I want to read configuration directives. I used the following example out of “The Apache Modules Book” (Nick Kew).  It compiles fine, however, when I restart apache, I get segmentation fault:

sudo service apache2 restart
Segmentation fault (core dumped)
Action 'configtest' failed.
The Apache error log may have more information.
   …fail!

log shows this:

[Sun Dec 08 03:58:04 2013] [notice] child pid 30080 exit signal Segmentation fault (11), possible coredump in /etc/apache2

The fault seems to be a result of this line of code (no error results if it is removed):

  ((txt_cfg*)cfg)->header = val ;

Here is my code (reduced to minimal test case):


#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"

typedef struct txt_cfg {
  const char* header ;
  const char* footer ;
} txt_cfg;

static const char* get_form_path(cmd_parms* cmd, void* cfg,
  const char* val) {
  ((txt_cfg*)cfg)->header = val ;
  return NULL ;
}

static const command_rec mod_cmds[] = {
  AP_INIT_TAKE1("CustomAuthFormPath", get_form_path, NULL, OR_ALL,
        "Path to custom authorization form"),
  { NULL }
};

static void register_hooks(apr_pool_t *pool)
{
}

module AP_MODULE_DECLARE_DATA customauthform_module =
{
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    NULL,
    NULL,
    mod_cmds,
    register_hooks,
};

If anyone knows the reason for this I would surely appreciate understanding.

Thank you kindly,

Allasso


Re: [users@httpd] Seg fault when assigning value in AP_INIT_TAKE1 callback

Posted by Allasso Travesser <al...@gmail.com>.
Thank you for your input, Nick.  I see what you mean about using a full example; not yet understanding how modules work, it didn’t occur to me that cfg would be getting initialized somewhere else.  My c programming skills are also rudimentary.

Regarding mod_auth_form, I am using Apache 2.2.  I tried just loading a 2.4 module, but I get errors.  If I knew more about Apache and how modules work, I could probably understand why I am getting the errors.  Hence, the road I am on, as I find it helpful to learn this stuff anyway.  (I am on Ubuntu 10.04, and there is no official package for Apache 2.4 yet available, and being a nominal linux user I would rather stick with the mainstream)

Thanks for the help :-)

Allasso


On Dec 8, 2013, at 12:38 AM, Nick Kew <ni...@webthing.com> wrote:

> 
> On 8 Dec 2013, at 04:17, Allasso Travesser wrote:
> 
>> Hello,
>> 
>> Learning to create modules, I want to read configuration directives. I used the following example out of “The Apache Modules Book” (Nick Kew).  It compiles fine, however, when I restart apache, I get segmentation fault:
> 
> So why not start with a complete example, then reduce it step-by-step
> to what you have?  That way you see where it falls apart and figure out
> why what you just lost mattered.
> 
> In this case ...
> 
>> The fault seems to be a result of this line of code (no error results if it is removed):
>> 
>>  ((txt_cfg*)cfg)->header = val ;
> 
> … cfg needs to have been initialised, but ...
> 
>> module AP_MODULE_DECLARE_DATA customauthform_module =
>> {
>>    STANDARD20_MODULE_STUFF,
>>    NULL,
>>    NULL,
>>    NULL,
>>    NULL,
>>    mod_cmds,
>>    register_hooks,
>> };
> 
> … your initialisation function is NULL.
> 
> (judging by the name of your module, maybe the now-standard
> mod_auth_form would be a good startingpoint for you?)
> 
> -- 
> Nick Kew
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Seg fault when assigning value in AP_INIT_TAKE1 callback

Posted by Nick Kew <ni...@webthing.com>.
On 8 Dec 2013, at 04:17, Allasso Travesser wrote:

> Hello,
> 
> Learning to create modules, I want to read configuration directives. I used the following example out of “The Apache Modules Book” (Nick Kew).  It compiles fine, however, when I restart apache, I get segmentation fault:

So why not start with a complete example, then reduce it step-by-step
to what you have?  That way you see where it falls apart and figure out
why what you just lost mattered.

In this case ...

> The fault seems to be a result of this line of code (no error results if it is removed):
> 
>   ((txt_cfg*)cfg)->header = val ;

… cfg needs to have been initialised, but ...

> module AP_MODULE_DECLARE_DATA customauthform_module =
> {
>     STANDARD20_MODULE_STUFF,
>     NULL,
>     NULL,
>     NULL,
>     NULL,
>     mod_cmds,
>     register_hooks,
> };

… your initialisation function is NULL.

(judging by the name of your module, maybe the now-standard
mod_auth_form would be a good startingpoint for you?)

-- 
Nick Kew
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org