Check for safe use of `memcpy` before warnings
Finds vulnerabilities in C/C++ source code
Brought to you by:
dwheeler
In the nRF52 SDK, file components/libraries/crypto/backend/oberon/oberon_backend_chacha_poly_aead.c, for the line memcpy( p_ctx->key, p_key, sizeof(p_ctx->key) ) flawfinder reports:
Does not check for buffer overflows when copying to destination (CWE-120).
Make sure destination can always hold the source data.
Would it be reasonable to not throw this error when using memcpy with the pattern memcpy(a, b, sizeof(a))? In general I'd like to use flawfinder and memcpy without needing to explicitly ignore every use of memcpy in the code, when the uses are checked. I follow the policy that warnings are errors, and that my code should compile warning free.
Yes, that sounds very reasonable. Do you want to propose the patch to do that?
Used test vectors:
Patch attached - apply w/
git am 001-fix-19.patch.Last edit: Michael Clark 2018-12-19
Overall I like the solution. I have two comments:
If you can address those two things, I will gladly merge the patch. Thank you so much for your time.
I've cleaned up your 1. w/
([^)\s]*), added more whitespace checks, etc. For 2. I added 4 cases including whitespace checking and corresponding updates to the unit test suite. I agree that unit tests are nice, which is why I provided you with test vectors.Excellent! Thanks very much. Merged. Let me know of any other great ideas like that one!