From f1bb19d7087386e89b2332ff4e1ae128b534e341 Mon Sep 17 00:00:00 2001 From: Geoff Garside Date: Thu, 20 Oct 2011 10:18:49 +0100 Subject: [PATCH 1/3] Add NGX_FREEBSD support. Uses the FreeBSD uuid(3) libc uuid_create(3) and uuid_to_string(3) functions. --- ngx_x_rid_header_module.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ngx_x_rid_header_module.c b/ngx_x_rid_header_module.c index c26963d..068d986 100644 --- a/ngx_x_rid_header_module.c +++ b/ngx_x_rid_header_module.c @@ -4,7 +4,7 @@ #include #if (NGX_FREEBSD) -#error FreeBSD is not supported yet, sorry. +#include #elif (NGX_LINUX) #include #elif (NGX_SOLARIS) @@ -26,7 +26,16 @@ ngx_int_t ngx_x_rid_header_get_variable(ngx_http_request_t *r, ngx_http_variable } #if (NGX_FREEBSD) -#error FreeBSD is not supported yet, sorry. + uuid_t uuid; + uint32_t uuid_status; + uuid_create(&uuid, &uuid_status); + if ( uuid_status != uuid_s_ok ) { + return -1; + } + uuid_to_string(&uuid, (char **)&p, &uuid_status); + if ( uuid_status != uuid_s_ok ) { + return -1; + } #elif (NGX_LINUX) uuid_t* uuid; if ( uuid_create(&uuid) ) { From a386549235dd6a19c39734c7aba268a46e58d6a5 Mon Sep 17 00:00:00 2001 From: Geoff Garside Date: Tue, 25 Oct 2011 14:06:54 +0100 Subject: [PATCH 2/3] Fix bug where p was reallocated by uuid_to_string(3). Thanks to @gabor for pointing out this mistake to me. --- ngx_x_rid_header_module.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ngx_x_rid_header_module.c b/ngx_x_rid_header_module.c index 068d986..8e39c27 100644 --- a/ngx_x_rid_header_module.c +++ b/ngx_x_rid_header_module.c @@ -26,16 +26,23 @@ ngx_int_t ngx_x_rid_header_get_variable(ngx_http_request_t *r, ngx_http_variable } #if (NGX_FREEBSD) + char *p_tmp; uuid_t uuid; uint32_t uuid_status; uuid_create(&uuid, &uuid_status); if ( uuid_status != uuid_s_ok ) { return -1; } - uuid_to_string(&uuid, (char **)&p, &uuid_status); + uuid_to_string(&uuid, (char **)&p_tmp, &uuid_status); if ( uuid_status != uuid_s_ok ) { return -1; } + + if ( memmove(p, p_tmp, 36) < 0 ) { + free(p_tmp); + return -1; + } + free(p_tmp); #elif (NGX_LINUX) uuid_t* uuid; if ( uuid_create(&uuid) ) { From 014ea3cdc7c2c9ea35c9179e269b07ea0397c697 Mon Sep 17 00:00:00 2001 From: Geoff Garside Date: Tue, 25 Oct 2011 14:18:00 +0100 Subject: [PATCH 3/3] Copy all 37 bytes of memory to p as its not zero'd. --- ngx_x_rid_header_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngx_x_rid_header_module.c b/ngx_x_rid_header_module.c index 8e39c27..3d55320 100644 --- a/ngx_x_rid_header_module.c +++ b/ngx_x_rid_header_module.c @@ -38,7 +38,7 @@ ngx_int_t ngx_x_rid_header_get_variable(ngx_http_request_t *r, ngx_http_variable return -1; } - if ( memmove(p, p_tmp, 36) < 0 ) { + if ( memmove(p, p_tmp, 37) < 0 ) { free(p_tmp); return -1; }