Skip to content
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

bugfix: wip: Set headers in the tail of a list rather than in the head #2182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oxpa
Copy link
Contributor

@oxpa oxpa commented Apr 22, 2023

It seems that ngx_http_variable_headers_internal function in nginx/src/http/ngx_http_variables.c relies on the fact that the last header values is stored in the last element of a list. Therefore we should avoid changing a random element in the head of a list of headers and either change the last element or add a new element to the list.

Not sure if this is the proper fix.
Thanks to @ssdr for pointing out the problem in #2177

I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.

It seems that ngx_http_variable_headers_internal function in
nginx/src/http/ngx_http_variables.c relies on the fact that the
last header values is stored in the last element of a list.
Therefore we should avoid changing a random element in the head of
a list of headers and either change the last element or add a new
element to the list.
@oxpa oxpa changed the title Set headers in the tail of a list rather than in the head bugfix: wip: Set headers in the tail of a list rather than in the head Apr 22, 2023

h = *headers;

if (h->hash == 0) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, I'm afraid here h is NULL ptr after last for loop iterate...


for (ph = headers; *ph; ph = &(*ph)->next) { /* void */ }
} else {
ho = ngx_list_push(&r->headers_out.headers);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when last element is valid and other elements are not, here will make a new element, right? Does it mean that the invalid elements never be reused in pool? So why not just nullifying the first element next for simplicity?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually when set builtin multi input header, it just nullifying the next pointer.

can we do same thing for output headers?

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

Successfully merging this pull request may close these issues.

2 participants