From a2895a03d9cc73988920ab351d6489dae6d5058f Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Wed, 2 Jun 2021 21:00:06 +0300 Subject: [PATCH 1/3] Try to fix #317 - check for session vars and add ampersand only if they exists --- ngx_rtmp_netcall_module.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ngx_rtmp_netcall_module.c b/ngx_rtmp_netcall_module.c index 24c001c..80144c8 100644 --- a/ngx_rtmp_netcall_module.c +++ b/ngx_rtmp_netcall_module.c @@ -572,6 +572,7 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool) ngx_buf_t *b; ngx_str_t *addr_text; size_t bsize; + ngx_char_t has_vars; addr_text = &s->connection->addr_text; @@ -586,25 +587,36 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool) * So not override them with empty values */ - bsize = sizeof("&addr=") - 1 + addr_text->len * 3 + + bsize = sizeof("addr=") - 1 + addr_text->len * 3 + sizeof("&clientid=") - 1 + NGX_INT_T_LEN; + // Indicator of additional vars from session + // Event `connect` don't have them, for example + has_vars = 0; if (s->app.len) { bsize += sizeof("app=") - 1 + s->app.len * 3; + has_vars = 1; } if (s->flashver.len) { bsize += sizeof("&flashver=") - 1 + s->flashver.len * 3; + has_vars = 1; } if (s->swf_url.len) { bsize += sizeof("&swfurl=") - 1 + s->swf_url.len * 3; + has_vars = 1; } if (s->tc_url.len) { bsize += sizeof("&tcurl=") - 1 + s->tc_url.len * 3; + has_vars = 1; } if (s->page_url.len) { bsize += sizeof("&pageurl=") - 1 + s->page_url.len * 3; + has_vars = 1; } + // We will add concatenating '&' later + if (0 !== has_vars) bsize += 1; + b = ngx_create_temp_buf(pool, bsize); if (b == NULL) { return NULL; @@ -643,7 +655,10 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool) s->page_url.len, NGX_ESCAPE_ARGS); } - b->last = ngx_cpymem(b->last, (u_char*) "&addr=", sizeof("&addr=") - 1); + // We have additional vars in session + if (has_vars) *b->last++ = '&'; + + b->last = ngx_cpymem(b->last, (u_char*) "addr=", sizeof("addr=") - 1); b->last = (u_char*) ngx_escape_uri(b->last, addr_text->data, addr_text->len, NGX_ESCAPE_ARGS); From 1688a23f0a2d06aa6b4ba03c8846a710529e5dc4 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Wed, 2 Jun 2021 21:08:37 +0300 Subject: [PATCH 2/3] Simplify request string format --- ngx_rtmp_netcall_module.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/ngx_rtmp_netcall_module.c b/ngx_rtmp_netcall_module.c index 80144c8..9ffadde 100644 --- a/ngx_rtmp_netcall_module.c +++ b/ngx_rtmp_netcall_module.c @@ -572,7 +572,6 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool) ngx_buf_t *b; ngx_str_t *addr_text; size_t bsize; - ngx_char_t has_vars; addr_text = &s->connection->addr_text; @@ -592,31 +591,22 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool) // Indicator of additional vars from session // Event `connect` don't have them, for example - has_vars = 0; if (s->app.len) { - bsize += sizeof("app=") - 1 + s->app.len * 3; - has_vars = 1; + bsize += sizeof("&app=") - 1 + s->app.len * 3; } if (s->flashver.len) { bsize += sizeof("&flashver=") - 1 + s->flashver.len * 3; - has_vars = 1; } if (s->swf_url.len) { bsize += sizeof("&swfurl=") - 1 + s->swf_url.len * 3; - has_vars = 1; } if (s->tc_url.len) { bsize += sizeof("&tcurl=") - 1 + s->tc_url.len * 3; - has_vars = 1; } if (s->page_url.len) { bsize += sizeof("&pageurl=") - 1 + s->page_url.len * 3; - has_vars = 1; } - // We will add concatenating '&' later - if (0 !== has_vars) bsize += 1; - b = ngx_create_temp_buf(pool, bsize); if (b == NULL) { return NULL; @@ -625,8 +615,16 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool) cl->buf = b; cl->next = NULL; + b->last = ngx_cpymem(b->last, (u_char*) "addr=", sizeof("addr=") - 1); + b->last = (u_char*) ngx_escape_uri(b->last, addr_text->data, + addr_text->len, NGX_ESCAPE_ARGS); + + b->last = ngx_cpymem(b->last, (u_char*) "&clientid=", + sizeof("&clientid=") - 1); + b->last = ngx_sprintf(b->last, "%ui", (ngx_uint_t) s->connection->number); + if (s->app.len) { - b->last = ngx_cpymem(b->last, (u_char*) "app=", sizeof("app=") - 1); + b->last = ngx_cpymem(b->last, (u_char*) "&app=", sizeof("&app=") - 1); b->last = (u_char*) ngx_escape_uri(b->last, s->app.data, s->app.len, NGX_ESCAPE_ARGS); } @@ -655,17 +653,6 @@ ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s, ngx_pool_t *pool) s->page_url.len, NGX_ESCAPE_ARGS); } - // We have additional vars in session - if (has_vars) *b->last++ = '&'; - - b->last = ngx_cpymem(b->last, (u_char*) "addr=", sizeof("addr=") - 1); - b->last = (u_char*) ngx_escape_uri(b->last, addr_text->data, - addr_text->len, NGX_ESCAPE_ARGS); - - b->last = ngx_cpymem(b->last, (u_char*) "&clientid=", - sizeof("&clientid=") - 1); - b->last = ngx_sprintf(b->last, "%ui", (ngx_uint_t) s->connection->number); - return cl; } From 5cb0be7f09477070911922774294af89ddfc04bf Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Wed, 2 Jun 2021 21:23:09 +0300 Subject: [PATCH 3/3] Fix warning-error about reproducible builds --- ngx_rtmp_stat_module.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ngx_rtmp_stat_module.c b/ngx_rtmp_stat_module.c index 8d21c8b..265d951 100644 --- a/ngx_rtmp_stat_module.c +++ b/ngx_rtmp_stat_module.c @@ -833,7 +833,10 @@ ngx_rtmp_stat_handler(ngx_http_request_t *r) #ifdef NGX_COMPILER NGX_RTMP_STAT_L("" NGX_COMPILER "\r\n"); #endif +/* This may prevent reproducible builds. If you need that info - pass `-DNGX_BUILD_DATEITIME=1` to CFLAGS */ +#ifdef NGX_BUILD_DATEITIME NGX_RTMP_STAT_L("" __DATE__ " " __TIME__ "\r\n"); +#endif NGX_RTMP_STAT_L(""); NGX_RTMP_STAT(nbuf, ngx_snprintf(nbuf, sizeof(nbuf),