yaoweibin / ngx_http_substitutions_filter_module

a filter module which can do both regular expression and fixed string substitutions for nginx
607 stars 213 forks source link

potential incorrect check in ngx_http_subs_init_context #51

Open leeriorio opened 1 month ago

leeriorio commented 1 month ago

In result of static analyse of nginx sources (including this module) code with Svace static analyzer I found error of cathegory "NULL_AFTER_DEREF" (situations where first, a pointer is dereferenced, and then it is compared to null) in ngx_http_subs_filter_module.c

the problem affects ngx_http_subs_init_context() function on lines 295-299

https://github.com/yaoweibin/ngx_http_substitutions_filter_module/blob/master/ngx_http_subs_filter_module.c#L295-L299

294
295    ctx->sub_pairs = ngx_array_create(r->pool, slcf->sub_pairs->nelts,
296                                      sizeof(sub_pair_t));
297    if (slcf->sub_pairs == NULL) {
298        return NGX_ERROR;
299    }
300

Is it correct to compare slcf->sub_pairs with NULL in line 297 after dereference of it in line 295? Should it be ctx->sub_pairs instead of slcf->sub_pairs in comparison?