Fix the overrun issue reported by static application security testing#177
Open
lian-bo wants to merge 1 commit intogoogle:mainfrom
Open
Fix the overrun issue reported by static application security testing#177lian-bo wants to merge 1 commit intogoogle:mainfrom
lian-bo wants to merge 1 commit intogoogle:mainfrom
Conversation
The current issue is reported by the SAST(Static Application Security Testing) as below: Error: OVERRUN: snappy_unittest.cc:95: return_constant: Function call "sysconf(_SC_PAGESIZE)" may return -1. snappy_unittest.cc:95: assignment: Assigning: "page_size" = "sysconf(_SC_PAGESIZE)". The value of "page_size" is now 18446744073709551615. snappy_unittest.cc:97: overrun-buffer-arg: Calling "mprotect" with "this->protected_page_" and "page_size" is suspicious because of the very large index, 18446744073709551615. The index may be due to a negative parameter being interpreted as unsigned. # 95| const size_t page_size = sysconf(_SC_PAGESIZE); # 96| // Undo the mprotect. # 97|-> CHECK_EQ(0, mprotect(protected_page_, page_size, PROT_READ|PROT_WRITE)); # 98| CHECK_EQ(0, munmap(mem_, alloc_size_)); # 99| } Let's set the page size to 4096, if the invoking sysconf(_SC_PAGESIZE) failed, otherwise still use the actual value of sysconf(_SC_PAGESIZE). In addition, also save its value in the constructor function in order to use it again in the deconstructor function, that can avoid calling the sysconf(_SC_PAGESIZE) twice. (Did the same changes in snappy_test_tool.cc). Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
Thank you for applying the patch: ee6bc15 ("Fix the overrun issue reported by static application security testing") |
Author
|
Hi, @danilak-G |
Collaborator
|
Thanks for the patch. This is low priority for now as this affects only a testing tool and unittests without affecting core code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The current issue is reported by the SAST(Static Application Security Testing) as below:
Error: OVERRUN:
snappy_unittest.cc:95: return_constant: Function call "sysconf(_SC_PAGESIZE)" may return -1.
snappy_unittest.cc:95: assignment: Assigning: "page_size" = "sysconf(SC_PAGESIZE)". The value of "page_size" is now 18446744073709551615.
snappy_unittest.cc:97: overrun-buffer-arg: Calling "mprotect" with "this->protected_page" and "page_size" is suspicious because of the very large index, 18446744073709551615. The index may be due to a negative parameter being interpreted as unsigned.
95| const size_t page_size = sysconf(_SC_PAGESIZE);
96| // Undo the mprotect.
97|-> CHECK_EQ(0, mprotect(protected_page_, page_size, PROT_READ|PROT_WRITE));
98| CHECK_EQ(0, munmap(mem_, alloc_size_));
99| }
Let's set the page size to 4096, if the invoking sysconf(_SC_PAGESIZE) failed, otherwise still use the actual value of sysconf(_SC_PAGESIZE). In addition, also save its value in the constructor function in order to use it again in the deconstructor function, that can avoid calling the sysconf(_SC_PAGESIZE) twice.
(Did the same changes in snappy_test_tool.cc).