[PATCH 1 of 1] fix crash with ngx_setproctitle

Maxim Dounin mdounin at mdounin.ru
Sun Aug 17 19:03:59 UTC 2014


Hello!

On Sun, Aug 17, 2014 at 09:23:04PM +0300, Markus Linnala wrote:

> # HG changeset patch
> # User Markus Linnala <Markus.Linnala at cybercom.com>
> # Date 1408298513 -10800
> #      Sun Aug 17 21:01:53 2014 +0300
> # Node ID 5524fc592881550bc5ed108993af148ebd09fa22
> # Parent  79553cb7774753f9c40a6fa6744b0e0611e41908
> fix crash with ngx_setproctitle
> 
> Test ngx_init_setproctitle return value to prevent crash at ngx_setproctitle.
> 
> diff -r 79553cb77747 -r 5524fc592881 src/os/unix/ngx_posix_init.c
> --- a/src/os/unix/ngx_posix_init.c	Fri Aug 15 14:09:29 2014 +0400
> +++ b/src/os/unix/ngx_posix_init.c	Sun Aug 17 21:01:53 2014 +0300
> @@ -40,7 +40,9 @@
>      }
>  #endif
>  
> -    ngx_init_setproctitle(log);
> +    if (ngx_init_setproctitle(log) != NGX_OK) {
> +        return NGX_ERROR;
> +    }
>  
>      ngx_pagesize = getpagesize();
>      ngx_cacheline_size = NGX_CPU_CACHE_LINE;

This is at least incomplete, it will only work for platforms where 
ngx_init_setproctitle() actually does something.  It break things 
for platforms with setproctitle() and platforms where 
setproctitle() can't be emulated.

At least something like this is needed:

--- a/src/os/unix/ngx_setproctitle.h
+++ b/src/os/unix/ngx_setproctitle.h
@@ -13,7 +13,7 @@
 
 /* FreeBSD, NetBSD, OpenBSD */
 
-#define ngx_init_setproctitle(log)
+#define ngx_init_setproctitle(log) NGX_OK
 #define ngx_setproctitle(title)    setproctitle("%s", title)
 
 
@@ -39,7 +39,7 @@ void ngx_setproctitle(char *title);
 
 #else
 
-#define ngx_init_setproctitle(log)
+#define ngx_init_setproctitle(log) NGX_OK
 #define ngx_setproctitle(title)
 
 #endif /* OSes */


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



More information about the nginx-devel mailing list