diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs index 6acc4f8a0..af8549661 100644 --- a/src/http/modules/perl/nginx.xs +++ b/src/http/modules/perl/nginx.xs @@ -18,6 +18,9 @@ #define ngx_http_perl_set_request(r, ctx) \ \ ctx = INT2PTR(ngx_http_perl_ctx_t *, SvIV((SV *) SvRV(ST(0)))); \ + if (ctx != ngx_http_perl_active_context || ctx == NULL) { \ + croak("invalid request object"); \ + } \ r = ctx->request diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c index 946ddf846..300cd5e0a 100644 --- a/src/http/modules/perl/ngx_http_perl_module.c +++ b/src/http/modules/perl/ngx_http_perl_module.c @@ -148,6 +148,9 @@ static ngx_http_ssi_command_t ngx_http_perl_ssi_command = { #endif +ngx_http_perl_ctx_t *ngx_http_perl_active_context; + + static ngx_str_t ngx_null_name = ngx_null_string; static HV *nginx_stash; @@ -746,6 +749,8 @@ ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, PUSHMARK(sp); + ngx_http_perl_active_context = ctx; + sv = sv_2mortal(sv_bless(newRV_noinc(newSViv(PTR2IV(ctx))), nginx)); XPUSHs(sv); @@ -790,6 +795,8 @@ ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, FREETMPS; LEAVE; + ngx_http_perl_active_context = NULL; + if (ctx->error) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, diff --git a/src/http/modules/perl/ngx_http_perl_module.h b/src/http/modules/perl/ngx_http_perl_module.h index 27eea9ada..2747389a9 100644 --- a/src/http/modules/perl/ngx_http_perl_module.h +++ b/src/http/modules/perl/ngx_http_perl_module.h @@ -59,6 +59,9 @@ typedef struct { extern ngx_module_t ngx_http_perl_module; +extern ngx_http_perl_ctx_t *ngx_http_perl_active_context; + + /* * workaround for "unused variable `Perl___notused'" warning * when building with perl 5.6.1