posix.cfg,gnu.cfg: Add (get|set)hostname functions. (#1315)

Reference for POSIX gethostname:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/gethostname.html
Reference for sethostname:
http://man7.org/linux/man-pages/man2/gethostname.2.html
This commit is contained in:
Sebastian 2018-07-18 09:40:06 +02:00 committed by GitHub
parent e46c499f5a
commit 4ef452132c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 0 deletions

View File

@ -705,6 +705,19 @@
<not-uninit/>
</arg>
</function>
<!-- int sethostname(const char *name, size_t len); -->
<function name="sethostname">
<noreturn>false</noreturn>
<returnValue type="int"/>
<arg nr="1">
<not-null/>
<minsize type="argvalue" arg="2"/>
</arg>
<arg nr="2">
<not-uninit/>
<valid>0:</valid>
</arg>
</function>
<resource>
<dealloc>close</dealloc>
<alloc init="true">epoll_create</alloc>

View File

@ -3849,6 +3849,19 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
<returnValue type="void"/>
<noreturn>false</noreturn>
</function>
<!-- int gethostname(char *name, size_t len); -->
<function name="gethostname">
<noreturn>false</noreturn>
<returnValue type="int"/>
<arg nr="1">
<not-null/>
<minsize type="argvalue" arg="2"/>
</arg>
<arg nr="2">
<not-uninit/>
<valid>1:</valid>
</arg>
</function>
<memory>
<alloc init="true">strdup</alloc>
<alloc init="true">strndup</alloc>

View File

@ -9,6 +9,15 @@
#include <string.h>
void bufferAccessOutOfBounds()
{
char buf[2];
// This is valid
sethostname(buf, 2);
// cppcheck-suppress bufferAccessOutOfBounds
sethostname(buf, 4);
}
void leakReturnValNotUsed()
{
// cppcheck-suppress unreadVariable

View File

@ -48,6 +48,10 @@ void bufferAccessOutOfBounds(int fd)
readlinkat(1, "path", a, 5);
// cppcheck-suppress bufferAccessOutOfBounds
readlinkat(1, "path", a, 6);
// This is valid
gethostname(a, 5);
// cppcheck-suppress bufferAccessOutOfBounds
gethostname(a, 6);
}
void nullPointer(char *p, int fd)