From 2620802c9f6304882cd6ff33270775c7c38b4cd8 Mon Sep 17 00:00:00 2001 From: Huzaifa Sidhpurwala Date: Sat, 18 Sep 2021 11:00:46 +0530 Subject: [PATCH] some more C-lib specific advice --- modules/ROOT/pages/programming-languages/C-Libc.adoc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/ROOT/pages/programming-languages/C-Libc.adoc b/modules/ROOT/pages/programming-languages/C-Libc.adoc index 3cb4b53..3708871 100644 --- a/modules/ROOT/pages/programming-languages/C-Libc.adoc +++ b/modules/ROOT/pages/programming-languages/C-Libc.adoc @@ -288,7 +288,8 @@ them to find out what the length actually means. === Using tricky syscalls or library functions ==== `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 bufsize should be `sizeof(buf) - 1` * `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 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.