Skip to content

Array push check #1792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Fahnenfluchtige
Copy link

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;
+    }
+    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant