Welcome! Log In Create A New Profile

Advanced

Re: ngx_reopen_files() assumes null termination

Maxim Dounin
March 11, 2014 08:14AM
Hello!

On Tue, Mar 11, 2014 at 02:32:52PM +1100, Andrew Punch wrote:

> I just noticed that ngx_reopen_files() treats the file name as a null
> terminated string but there is no guarantee that a ngx_str_t will be null
> terminated.

While ngx_str_t strings aren't required to be null-terminated, in
some cases terminating null is required, and file names is one of
such cases (because file names must be null-terminated for
syscalls).

There are also some cases where ngx_str_t strings are guaranteed
to be null-terminated - e.g., arguments of configuration
directives as seen during configuration parsing are
null-terminated.

Usually there are easy ways to explicitly request null-termination
where it may be required but nog guaranteed. E.g., complex values
have "zero" flag, which may be set during compilation and results
in trailing zero added to values returned at runtime. See
auth_basic_user_file implementation which uses it.

> I noticed in ngx_string.h that the ngx_string() macro sets the length to be
> exclusive of the null termination character, however the null termination
> would still be present at s.data[s.len]
>
> However ngx_pstrdup() in ngx_string.c only copies the size of s.len - so if
> there is a null character at s.data[s.len] it will not be copied.
>
> Could you please help clarify the correct way to handle the strings?

Trailing null should be handled explicitly when needed.

--
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

ngx_reopen_files() assumes null termination

Andrew Punch 723 March 10, 2014 11:34PM

Re: ngx_reopen_files() assumes null termination

Maxim Dounin 576 March 11, 2014 08:14AM



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

Online Users

Guests: 160
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