From 78715d3eff92db99c4e6468d537c2dc49ef4275d Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 16 Aug 2018 21:37:40 +0200 Subject: [PATCH] bsd.cfg: Add arc4random* functions with tests. (#1344) Reference: https://www.freebsd.org/cgi/man.cgi?query=arc4random --- cfg/bsd.cfg | 47 +++++++++++++++++++++++++++++++++++++++++++++++ test/cfg/bsd.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/cfg/bsd.cfg b/cfg/bsd.cfg index 72c356283..67ad8a4fa 100644 --- a/cfg/bsd.cfg +++ b/cfg/bsd.cfg @@ -176,6 +176,53 @@ 0: + + + + false + + + + + + false + + + + + + + + + 1: + + + + + false + + + + + 2: + + + + + false + + + + false + + + + + + + 0: + + diff --git a/test/cfg/bsd.c b/test/cfg/bsd.c index 44227b71a..b7e4bed61 100644 --- a/test/cfg/bsd.c +++ b/test/cfg/bsd.c @@ -7,6 +7,8 @@ // #include +#include +#include // size_t strlcat(char *dst, const char *src, size_t size); void uninitvar_strlcat(char *Ct, const char *S, size_t N) @@ -26,3 +28,42 @@ void uninitvar_strlcat(char *Ct, const char *S, size_t N) // no warning is expected for (void)strlcat(Ct,S,N); } + +void bufferAccessOutOfBounds(void) +{ + uint16_t uint16Buf[4]; + // cppcheck-suppress bufferAccessOutOfBounds + arc4random_buf(uint16Buf, 9); + // valid + arc4random_buf(uint16Buf, 8); +} + +void ignoredReturnValue(void) +{ + // cppcheck-suppress ignoredReturnValue + arc4random(); + // cppcheck-suppress ignoredReturnValue + arc4random_uniform(10); +} + +void invalidFunctionArg() +{ + // cppcheck-suppress invalidFunctionArg + (void) arc4random_uniform(1); + // valid + (void) arc4random_uniform(2); +} + +void nullPointer(void) +{ + // cppcheck-suppress nullPointer + arc4random_buf(NULL, 5); +} + +void uninitvar(void) +{ + uint32_t uint32Uninit; + + // cppcheck-suppress uninitvar + (void) arc4random_uniform(uint32Uninit); +}