some more C-lib specific advice
This commit is contained in:
parent
bce3587ece
commit
2620802c9f
1 changed files with 6 additions and 2 deletions
|
@ -288,7 +288,8 @@ them to find out what the length actually means.
|
||||||
|
|
||||||
=== Using tricky syscalls or library functions
|
=== Using tricky syscalls or library functions
|
||||||
==== `readlink`
|
==== `readlink`
|
||||||
This is the hardest system call to use correctly because of everything you have to do
|
This is the hardest system call to use correctly because of everything you have to do
|
||||||
|
|
||||||
* The buf should be of PATH_MAX length, that includes space for the terminating NUL character.
|
* The buf should be of PATH_MAX length, that includes space for the terminating NUL character.
|
||||||
* The bufsize should be `sizeof(buf) - 1`
|
* The bufsize should be `sizeof(buf) - 1`
|
||||||
* `readlink` return value should be caught as a signed integer (ideally type `ssize_t`).
|
* `readlink` return value should be caught as a signed integer (ideally type `ssize_t`).
|
||||||
|
@ -304,4 +305,7 @@ This is the hardest system call to use correctly because of everything you have
|
||||||
* If `S_ISLNK` macro is used, the stat buffer MUST come from lstat or from fstatat with `AT_SYMLINK_NOFOLLOW`
|
* If `S_ISLNK` macro is used, the stat buffer MUST come from lstat or from fstatat with `AT_SYMLINK_NOFOLLOW`
|
||||||
* If you are doing something really important, call fstat after opening and compare the before and after stat buffers before trusting them.
|
* If you are doing something really important, call fstat after opening and compare the before and after stat buffers before trusting them.
|
||||||
|
|
||||||
|
=== `setgid`, `setuid`:
|
||||||
|
* Call these in the right order: groups and then uid.
|
||||||
|
* Always check the return code.
|
||||||
|
* If `setgid` & `setuid` are used, supplemental groups are not reset. This must be done with setgroups or initgroups before the uid change.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue