bsd.cfg: Add arc4random* functions with tests. (#1344)

Reference: https://www.freebsd.org/cgi/man.cgi?query=arc4random
This commit is contained in:
Sebastian 2018-08-16 21:37:40 +02:00 committed by GitHub
parent f33c09f1a7
commit 78715d3eff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 0 deletions

View File

@ -176,6 +176,53 @@
<valid>0:</valid>
</arg>
</function>
<!-- https://www.freebsd.org/cgi/man.cgi?query=arc4random -->
<!-- uint32_t arc4random(void); -->
<function name="arc4random">
<noreturn>false</noreturn>
<returnValue type="uint32_t"/>
<use-retval/>
</function>
<!-- void arc4random_buf(void *buf, size_t nbytes); -->
<function name="arc4random_buf">
<noreturn>false</noreturn>
<returnValue type="void"/>
<leak-ignore/>
<arg nr="1">
<not-null/>
<minsize type="argvalue" arg="2"/>
</arg>
<arg nr="2">
<not-uninit/>
<valid>1:</valid>
</arg>
</function>
<!-- uint32_t arc4random_uniform(uint32_t upper_bound); -->
<function name="arc4random_uniform">
<noreturn>false</noreturn>
<returnValue type="uint32_t"/>
<use-retval/>
<arg nr="1">
<not-uninit/>
<valid>2:</valid>
</arg>
</function>
<!-- void arc4random_stir(void); -->
<function name="arc4random_stir">
<noreturn>false</noreturn>
</function>
<!-- void arc4random_addrandom(unsigned char *dat, int datlen); -->
<function name="arc4random_addrandom">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<minsize type="argvalue" arg="2"/>
</arg>
<arg nr="2">
<not-uninit/>
<valid>0:</valid>
</arg>
</function>
<podtype name="FTS"/>
<podtype name="FTSENT"/>
</def>

View File

@ -7,6 +7,8 @@
//
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
// 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);
}