early ngx_memcpy() with NGX_MEMCPY_LIMIT patch

Maxim Dounin mdounin at mdounin.ru
Mon Jul 30 22:03:23 UTC 2012


Hello!

On Mon, Jul 30, 2012 at 10:24:49PM +0400, Vladimir Shebordaev wrote:

> Hi,
> 
> ngx_memcpy() is invoked before ngx_cycle has been initialized, so the server
> can segfault there when NGX_MEMCPY_LIMIT is enabled.
> 
> diff -Naur rev4754/src/core/ngx_string.c ticket55/src/core/ngx_string.c
> --- rev4754/src/core/ngx_string.c       2012-07-16 23:15:16.613980918 +0400
> +++ ticket55/src/core/ngx_string.c      2012-07-23 15:41:02.863561192 +0400
> @@ -1830,7 +1830,8 @@
>  ngx_memcpy(void *dst, void *src, size_t n)
>  {
>      if (n > NGX_MEMCPY_LIMIT) {
> -        ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "memcpy %uz bytes", n);
> +        if (ngx_cycle)
> +           ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "memcpy
> %uz bytes", n);
>          ngx_debug_point();
>      }

This change is certainly not enough for nginx to survive too low 
NGX_MEMCPY_LIMIT set, e.g. due to the fact that ngx_debug_point() 
needs ngx_cycle as well (and actually much more than this: it 
depends on a ngx_core_module config to be available via ngx_cycle).

I would rather suggest to don't try to define NGX_MEMCPY_LIMIT 
unless you understand possible implications.

Maxim Dounin



More information about the nginx-devel mailing list