[PATCH] ngx_pstrdup() and ngx_copy() problems

Maxim Dounin mdounin at mdounin.ru
Tue Dec 22 15:21:03 UTC 2015


Hello!

On Tue, Dec 22, 2015 at 05:57:25PM +0300, Sergey Matveychuk wrote:

> Yes, I wrong with ngx_copy.
> 
> But I see ngx_string_t data is passed to С functions. Just a first example
> I've found in ngx_open_file_wrapper():
> fd = ngx_open_file(name->data, mode, create, access);
> 
> Where ngx_open_file() is a macro for open(2).

When a string is expected to be used to call a library function 
which accepts null-terminated strings, it's up to the caller to 
ensure the string passed is properly null-terminated.

In some cases it happens automatically (e.g., strings from 
configuration parser are null-terminated), while in other cases 
you'll have to do it explicitly (e.g., in ngx_init_zone_pool() 
special format specifier %Z is used to generate a null-terminated 
name of a lock file).

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



More information about the nginx-devel mailing list