Fix: ngx_strncpy_s security fix #33
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello! I was analyzing your module with Svace SAST tool and found vulnerability in
ngx_strncpy_s. The problem is ngx_palloc function return value not being checked though it should. Here is source code:ngx_http_auth_pam_module/ngx_http_auth_pam_module.c
Lines 258 to 266 in d9429ba
ngx_pallocis guaranteed not to return NULL only if free space exists for the variable in one of the existing pools in the linked list (refer to howngx_palloc_smallworks). We cannot guarantee with absolute certainty that such space will always be available. If space is unavailable, memory allocation will be triggered: firstngx_palloc_blockwill be called, followed byngx_memalign, which internally allocates memory viaposix_memalignormemalign. These functions may return NULL. Therefore, ngx_palloc and functions using it should always be checked.I've changed function return type, now it returns
NGX_OKorNGX_ERRORandchar*variable is passed as one of the arguments. If allocation failed server will returnNGX_HTTP_INTERNAL_SERVER_ERROR. The chance it will happen is pretty low but it still may happen.Found by Linux Verification Center (linuxtesting.org) with SVACE.