Skip to content

Commit 5a7c998

Browse files
committed
posix.cfg: Improved configuration of getpwuid_r().
1 parent 8cc16f1 commit 5a7c998

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

cfg/posix.cfg

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,17 +3396,21 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
33963396
</arg>
33973397
<warn severity="portability">Non reentrant function 'getpwuid' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwuid_r'.</warn>
33983398
</function>
3399-
<!-- https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpwuid.html -->
3400-
<!-- int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result); -->
3399+
<!-- https://man7.org/linux/man-pages/man3/getpwnam.3.html -->
3400+
<!-- int getpwuid_r(uid_t uid, struct passwd *restrict pwd, char *restrict buf, size_t buflen, struct passwd **restrict result) -->
34013401
<function name="getpwuid_r">
34023402
<returnValue type="int"/>
3403+
<use-retval/>
34033404
<noreturn>false</noreturn>
34043405
<arg nr="1" direction="in">
34053406
<not-uninit/>
34063407
<not-bool/>
34073408
</arg>
3408-
<arg nr="2" direction="out"/>
3409+
<arg nr="2" direction="out">
3410+
<not-null/>
3411+
</arg>
34093412
<arg nr="3" direction="out">
3413+
<not-null/>
34103414
<minsize type="argvalue" arg="4"/>
34113415
</arg>
34123416
<arg nr="4" direction="in">
@@ -3416,6 +3420,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
34163420
</arg>
34173421
<arg nr="5" direction="out">
34183422
<not-bool/>
3423+
<not-null/>
34193424
</arg>
34203425
</function>
34213426
<!-- void setpwent(void); -->

test/cfg/posix.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
#include <string.h>
3636
#include <strings.h>
3737

38+
int nullPointer_getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
39+
{
40+
// cppcheck-suppress nullPointer
41+
(void) getpwuid_r(uid, NULL, buffer, bufsize, result);
42+
// cppcheck-suppress nullPointer
43+
(void) getpwuid_r(uid, pwd, NULL, bufsize, result);
44+
// cppcheck-suppress nullPointer
45+
(void) getpwuid_r(uid, pwd, buffer, bufsize, NULL);
46+
return getpwuid_r(uid, pwd, buffer, bufsize, result);
47+
}
48+
3849
int nullPointer_getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
3950
{
4051
// cppcheck-suppress nullPointer

0 commit comments

Comments
 (0)