summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules/perl (follow)
AgeCommit message (Collapse)AuthorFilesLines
2022-06-14Perl: removed unused variables, forgotten in ef6a3a99a81a.Sergey Kandaurov1-2/+1
2022-05-30All known output headers can be linked lists now.Maxim Dounin1-0/+1
The h->next pointer properly provided as NULL in all cases where known output headers are added. Note that there are 3rd party modules which might not do this, and it might be risky to rely on this for arbitrary headers.
2022-05-30Perl: combining unknown headers during $r->header_in() lookup.Maxim Dounin1-40/+44
2022-05-30Perl: all known input headers are handled identically.Maxim Dounin1-20/+2
As all known input headers are now linked lists, these are now handled identically. In particular, this makes it possible to access properly combined values of headers not specifically handled previously, such as "Via" or "Connection".
2022-05-30Reworked multi headers to use linked lists.Maxim Dounin1-13/+9
Multi headers are now using linked lists instead of arrays. Notably, the following fields were changed: r->headers_in.cookies (renamed to r->headers_in.cookie), r->headers_in.x_forwarded_for, r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control u->headers_in.cookies (renamed to u->headers_in.set_cookie). The r->headers_in.cookies and u->headers_in.cookies fields were renamed to r->headers_in.cookie and u->headers_in.set_cookie to match header names. The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines() functions were changed accordingly. With this change, multi headers are now essentially equivalent to normal headers, and following changes will further make them equivalent.
2019-07-17Perl: removed unused variable, forgotten in 975d7ab37b39.Maxim Dounin1-1/+0
2019-07-12Perl: named locations in $r->internal_redirect().Maxim Dounin1-6/+12
2019-07-12Perl: expect escaped URIs in $r->internal_redirect().Maxim Dounin3-13/+9
Similarly to the change in 5491:74bfa803a5aa (1.5.9), we should accept properly escaped URIs and unescape them as needed, else it is not possible to handle URIs with question marks.
2019-07-12Perl: additional ctx->header_sent checks.Maxim Dounin2-0/+25
As we now have ctx->header_sent flag, it is further used to prevent duplicate $r->send_http_header() calls, prevent output before sending header, and $r->internal_redirect() after sending header. Further, $r->send_http_header() protected from calls after $r->internal_redirect().
2019-07-12Perl: avoid returning 500 if header was already sent.Maxim Dounin3-0/+7
Returning NGX_HTTP_INTERNAL_SERVER_ERROR if a perl code died after sending header will lead to a "header already sent" alert. To avoid it, we now check if header was already sent, and return NGX_ERROR instead if it was.
2019-07-12Perl: avoid redirects on errors.Maxim Dounin1-0/+2
Previously, redirects scheduled with $r->internal_redirect() were followed even if the code then died. Now these are ignored and nginx will return an error instead.
2019-07-12Perl: disabled unrelated calls from variable handlers.Maxim Dounin3-0/+50
Variable handlers are not expected to send anything to the client, cannot sleep or read body, and are not expected to modify the request. Added appropriate protection to prevent accidental foot shooting.
2019-07-12Perl: protection against duplicate $r->sleep() calls.Maxim Dounin1-0/+8
Duplicate $r->sleep() and/or $r->has_request_body() calls result in undefined behaviour (in practice, connection leaks were observed). To prevent this, croak() added in appropriate places.
2019-07-12Perl: handling of allocation errors.Maxim Dounin1-25/+51
Previously, allocation errors in nginx.xs were more or less ignored, potentially resulting in incorrect code execution in specific low-memory conditions. This is changed to use ctx->error bit and croak(), similarly to how output errors are now handled. Note that this is mostly a cosmetic change, as Perl itself exits on memory allocation errors, and hence nginx with Perl is hardly usable in low-memory conditions.
2019-07-12Perl: propagate errors.Maxim Dounin3-7/+90
When an error happens, the ctx->error bit is now set, and croak() is called to terminate further processing. The ctx->error bit is checked in ngx_http_perl_call_handler() to cancel further processing, and is also checked in various output functions - to make sure these won't be called if croak() was handled by an eval{} in perl code. In particular, this ensures that output chain won't be called after errors, as filters might not expect this to happen. This fixes some segmentation faults under low memory conditions. Also this stops request processing after filter finalization or request body reading errors. For cases where an HTTP error status can be additionally returned (for example, 416 (Requested Range Not Satisfiable) from the range filter), the ctx->status field is also added.
2019-07-12Perl: reworked perl module to pass ctx instead of request.Maxim Dounin3-94/+114
This ensures that correct ctx is always available, including after filter finalization. In particular, this fixes a segmentation fault with the following configuration: location / { image_filter test; perl 'sub { my $r = shift; $r->send_http_header(); $r->print("foo\n"); $r->print("bar\n"); }'; } This also seems to be the only way to correctly handle filter finalization in various complex cases, for example, when embedded perl is used both in the original handler and in an error page called after filter finalization.
2019-07-11Perl: removed unneeded NGX_DONE test.Maxim Dounin1-5/+0
The NGX_DONE test in ngx_http_perl_handle_request() was introduced in 1702:86bb52e28ce0, which also modified ngx_http_perl_call_handler() to return NGX_DONE with c->destroyed. The latter part was then removed in 3050:f54b02dbb12b, so NGX_DONE test is no longer needed.
2019-06-17Perl: disabled not_modified filter (ticket #1786).Maxim Dounin1-0/+2
Embedded perl does not set any request fields needed for conditional requests processing. Further, filter finalization in the not_modified filter can cause segmentation faults due to cleared ctx as in ticket #1786. Before 5fb1e57c758a (1.7.3) the not_modified filter was implicitly disabled for perl responses, as r->headers_out.last_modified_time was -1. This change restores this behaviour by using the explicit r->disable_not_modified flag. Note that this patch doesn't try to address perl module robustness against filter finalization and other errors returned from filter chains. It should be eventually reworked to handle errors instead of ignoring them.
2017-04-20Cleaned up r->headers_out.headers allocation error handling.Sergey Kandaurov1-0/+2
If initialization of a header failed for some reason after ngx_list_push(), leaving the header as is can result in uninitialized memory access by the header filter or the log module. The fix is to clear partially initialized headers in case of errors. For the Cache-Control header, the fix is to postpone pushing r->headers_out.cache_control until its value is completed.
2017-04-11Added support for the "308 Permanent Redirect" (ticket #877).Simon Leblanc1-0/+2
2017-04-02Moved handling of wev->delayed to the connection event handler.Maxim Dounin1-4/+1
With post_action or subrequests, it is possible that the timer set for wev->delayed will expire while the active subrequest write event handler is not ready to handle this. This results in request hangs as observed with limit_rate / sendfile_max_chunk and post_action (ticket #776) or subrequests (ticket #1228). Moving the handling to the connection event handler fixes the hangs observed, and also slightly simplifies the code.
2017-04-02Perl: fixed delaying subrequests.Maxim Dounin2-6/+11
Much like in limit_req, use the wev->delayed flag to ensure proper handling and interoperability with limit_rate.
2016-12-07Perl: added PERL_SET_INTERP().Maxim Dounin1-0/+8
For Perl compiled with threads, without PERL_SET_INTERP() the PL_curinterp remains set to the first interpreter created (that is, one created at original start). As a result after a reload Perl thinks that operations are done withing a thread, and, most notably, denies to change environment. For example, the following code properly works on original start, but fails after a reload: perl 'sub { my $r = shift; $r->send_http_header("text/plain"); $ENV{TZ} = "UTC"; $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n"); $ENV{TZ} = "Europe/Moscow"; $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n"); return OK; }'; To fix this, PERL_SET_INTERP() added anywhere where PERL_SET_CONTEXT() was previously used. Note that PERL_SET_INTERP() doesn't seem to be documented anywhere. Yet it is used in some other software, and also seems to be the only solution possible.
2016-11-01Perl: fixed optimization in SSI command handler.Maxim Dounin1-1/+1
As the pointer to the first argument was tested instead of the argument itself, array of arguments was always created, even if there were no arguments. Fix is to test args[0] instead of args. Found by Coverity (CID 1356862).
2016-09-20Perl: pass additional linker options to perl module.Konstantin Pavlov1-0/+2
Previously flags passed by --with-ld-opt were not used when building perl module, which meant hardening flags provided by package build systems were not applied.
2015-08-18Perl: prototyping behavior explicitly specified.Maxim Dounin1-0/+3
When prototyping behavior is not explicitly specified, xsubpp emits a message to stderr asking to do so (see ticket #608).
2015-08-18Perl: fixed warning about "sep" may be used uninitialized.Maxim Dounin1-9/+6
2014-06-19Perl: NULL-terminate argument list.Piotr Sikora1-1/+2
perl_parse() function expects argv/argc-style argument list, which according to the C standard must be NULL-terminated, that is: argv[argc] == NULL. This change fixes a crash (SIGSEGV) that could happen because of the buffer overrun during perl module initialization. Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2013-09-04Handling of ngx_int_t != intptr_t case.Maxim Dounin1-2/+2
Casts between pointers and integers produce warnings on size mismatch. To silence them, cast to (u)intptr_t should be used. Prevoiusly, casts to ngx_(u)int_t were used in some cases, and several ngx_int_t expressions had no casts. As of now it's mostly style as ngx_int_t is defined as intptr_t.
2013-08-20Backed out f1a91825730a and 7094bd12c1ff.Maxim Dounin1-3/+1
While ngx_get_full_name() might have a bit more descriptive arguments, the ngx_conf_full_name() is generally easier to use when parsing configuration and limits exposure of cycle->prefix / cycle->conf_prefix details.
2013-08-06Replaced ngx_conf_full_name() with ngx_get_full_name().Valentin Bartenev1-1/+3
The ngx_get_full_name() function takes more readable arguments list.
2013-07-29Perl: fixed syntax usage for C preprocessor directives.Sergey Kandaurov1-7/+4
As per perlxs, C preprocessor directives should be at the first non-whitespace of a line to avoid interpreting them as comments. #if and #endif are moved so that there are no blank lines before them to retain them as part of the function body.
2013-06-10Perl: fixed r->header_in("Cookie") (ticket #351).Maxim Dounin1-9/+27
It was broken by X-Forwarded-For related changes in f7fe817c92a2 (1.3.14) as hh->offset is no longer 0 for Cookie.
2013-05-11Perl: extra "return" removed.Maxim Dounin1-1/+1
2013-04-23Perl: request body handling fixed.Maxim Dounin1-3/+36
As of 1.3.9, chunked request body may be available with r->headers_in.content_length_n <= 0. Additionally, request body may be in multiple buffers even if r->request_body_in_single_buf was requested.
2013-04-19Configure: fixed perl Makefile generation (ticket #334).Maxim Dounin1-1/+1
Dependancy tracking introduced in r5169 were not handled absolute path names properly. Absolute names might appear in CORE_DEPS if --with-openssl or --with-pcre configure arguments are used to build OpenSSL/PCRE libraries. Additionally, revert part of r5169 to set NGX_INCS from Makefile variables. Makefile variables have $ngx_include_opt in them, which might result in wrong include paths being used. As a side effect, this also restores build with --with-http_perl_module and --without-http at the same time.
2013-04-10Configure: fixed nginx.so rebuild (broken by r5145).Maxim Dounin1-2/+4
To avoid further breaks it's now done properly, all the dependencies are now passed to Makefile.PL. While here, fixed include list passed to Makefile.PL to use Makefile variables rather than a list expanded during configure.
2013-03-28Simplified nginx version maintenance.Ruslan Ermilov1-1/+1
It's no longer necessary to update src/http/modules/perl/nginx.pm when version is bumped, as it's now derived from src/core/nginx.h.
2013-03-27Version bump.Maxim Dounin1-1/+1
2013-03-07Version bump.Valentin Bartenev1-1/+1
2013-02-19Version bump.Valentin Bartenev1-1/+1
2013-02-07Version bump.Maxim Dounin1-1/+1
2013-01-17Version bump.Ruslan Ermilov1-1/+1
2012-12-26Version bump.Ruslan Ermilov1-1/+1
2012-12-20Brought the link to ngx_http_perl_module documentation up to date.Ruslan Ermilov1-1/+1
2012-12-17Added checks that disallow adding a variable with an empty name.Ruslan Ermilov1-1/+1
Added variable name syntax checks to "geo" and "map" directives.
2012-12-13Fixed variable syntax checking in "set", "geo", "limit_conn_zone",Ruslan Ermilov1-1/+1
and "perl_set" directives.
2012-12-03Fixed build with embedded perl in certain setups (ticket #48).Ruslan Ermilov1-14/+3
2012-11-29Version bump.Maxim Dounin1-1/+1
2012-11-16Version bump.Ruslan Ermilov1-1/+1