Welcome! Log In Create A New Profile

Advanced

Re: header value null termination?

Maxim Dounin
August 25, 2014 10:34AM
Hello!

On Fri, Aug 22, 2014 at 12:30:22AM +0100, Steven Hartland wrote:

> I'm creating a module in which I needed to set some
> of the standard headers e.g. Content-Range and Range.
>
> Looking through the core source code the standard way
> to do this seems to be something like this:-
>
> r->headers_in.range->value.len =
> ngx_sprintf(r->headers_in.range->value.data,
> "bytes %O-%O/%O",
> range->start, range->end - 1,
> r->headers_out.content_length_n)
> - r->headers_in.range->value.data;
>
> This appears to write a string to value.data which
> is not \0 terminated hence when interacting with
> functions such as ngx_http_range_parse unpredictable
> behaviour follows as it expects the range header to
> be null terminated.
>
> So the question is:-
>
> Should header values be null terminated or should
> functions such as ngx_http_range_parse be updated
> to deal with non-null terminated strings?

The answer is: no.

In general, strings in nginx are not null terminated, and there is
no need to null-terminated them. In some cases though strings are
guaranteed to be null-terminated - notably, configuration
directive arguments are always null-terminated, as well as input
headers. The ngx_http_range_parse() uses an input header from
r->headers_in, and it's guaranteed to be null-terminated.

The problem is in the "sample" code you've provided though: it
tries to modify input headers in r->headers_in. This is wrong
thing to do.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

header value null termination?

steveh 788 August 21, 2014 07:32PM

Re: header value null termination?

Maxim Dounin 327 August 25, 2014 10:34AM

Re: header value null termination?

steveh 703 August 25, 2014 02:58PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 110
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready