nginx-rtmp-module
nginx-rtmp-module copied to clipboard
Array push check
The Svace static analysis tool identified a potential issue in the function ngx_rtmp_relay_postconfiguration, where the return value of ngx_array_push is not checked properly:
ch = ngx_array_push(&cmcf->amf);
The function сan return NGX_ERROR. However, no error handling is performed.
So, the solution is to add error checking:
diff --git a/ngx_rtmp_relay_module.c b/ngx_rtmp_relay_module.c
index e90a829..4eb04ac 100644
--- a/ngx_rtmp_relay_module.c
+++ b/ngx_rtmp_relay_module.c
@@ -1680,14 +1680,32 @@ ngx_rtmp_relay_postconfiguration(ngx_conf_t *cf)
ch = ngx_array_push(&cmcf->amf);
+ if (ch == NULL) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "relay: failed to add amf handler");
+ return NGX_ERROR;
+ }
+
ngx_str_set(&ch->name, "_result");
ch->handler = ngx_rtmp_relay_on_result;
ch = ngx_array_push(&cmcf->amf);
+ if (ch == NULL) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "relay: failed to add amf handler");
+ return NGX_ERROR;
+ }
+
ngx_str_set(&ch->name, "_error");
ch->handler = ngx_rtmp_relay_on_error;
ch = ngx_array_push(&cmcf->amf);
+ if (ch == NULL) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "relay: failed to add amf handler");
+ return NGX_ERROR;
+ }
+