New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngx_pagespeed crashes on start if there is no http block in config #1220

Closed
LinuxJedi opened this Issue Jul 5, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@LinuxJedi
Copy link

LinuxJedi commented Jul 5, 2016

It is plausible to have NGINX with Pagespeed compiled in but no HTTP block. For example the same NGINX binary used as a TCP/UDP or Mail only load balancer. In these cases the Pagespeed module expects the http configuration block and causes NGINX to segfault.

@oschaaf

This comment has been minimized.

Copy link
Member

oschaaf commented Jul 5, 2016

Reproduced. Can you try and confirm if this fixes the problem?:

diff --git a/src/ngx_pagespeed.cc b/src/ngx_pagespeed.cc
index de60cfb..8676345 100644
--- a/src/ngx_pagespeed.cc
+++ b/src/ngx_pagespeed.cc
@@ -3014,7 +3014,7 @@ ngx_int_t ps_preaccess_handler(ngx_http_request_t* r) {
 ngx_int_t ps_etag_filter_init(ngx_conf_t* cf) {
   ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
       ngx_http_conf_get_module_main_conf(cf, ngx_pagespeed));
-  if (cfg_m->driver_factory != NULL) {
+  if (cfg_m != NULL && cfg_m->driver_factory != NULL) {
     ngx_http_ef_next_header_filter = ngx_http_top_header_filter;
     ngx_http_top_header_filter = ps_etag_header_filter;
   }
@@ -3096,6 +3096,11 @@ ngx_int_t ps_init_module(ngx_cycle_t* cycle) {
   ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
       ngx_http_cycle_get_module_main_conf(cycle, ngx_pagespeed));

+  // See https://github.com/pagespeed/ngx_pagespeed/issues/1220
+  if (cfg_m == NULL) {
+    return NGX_OK;
+  }
+
   ngx_http_core_main_conf_t* cmcf = static_cast<ngx_http_core_main_conf_t*>(
       ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module));
   ngx_http_core_srv_conf_t** cscfp = static_cast<ngx_http_core_srv_conf_t**>(
@@ -3163,7 +3168,7 @@ void ps_exit_child_process(ngx_cycle_t* cycle) {
   ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
       ngx_http_cycle_get_module_main_conf(cycle, ngx_pagespeed));
   NgxBaseFetch::Terminate();
-  if (cfg_m->driver_factory != NULL) {
+  if (cfg_m != NULL && cfg_m->driver_factory != NULL) {
     cfg_m->driver_factory->ShutDown();
   }
 }
@@ -3173,7 +3178,7 @@ void ps_exit_child_process(ngx_cycle_t* cycle) {
 ngx_int_t ps_init_child_process(ngx_cycle_t* cycle) {
   ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
       ngx_http_cycle_get_module_main_conf(cycle, ngx_pagespeed));
-  if (cfg_m->driver_factory == NULL) {
+  if (cfg_m == NULL || cfg_m->driver_factory == NULL) {
     return NGX_OK;
   }
@LinuxJedi

This comment has been minimized.

Copy link

LinuxJedi commented Jul 5, 2016

Perfect, in addition with this patch NGINX's test suite now passes 100% with Pagespeed compiled-in. Many thanks!

oschaaf added a commit that referenced this issue Jul 6, 2016

@crowell crowell changed the title Segment fault with no http block ngx_pagespeed crashes on start if there is no http block in config Aug 12, 2016

@crowell crowell closed this in ff89697 Aug 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment