opnsense-src/lib/libc
Stefan Eßer 23fe1083ca libc: return partial sysctl() result if buffer is too small
Testing of a new feature revealed that calling sysctl() to retrieve
the value of the user.localbase variable passing too low a buffer size
could leave the result buffer unchanged.

The behavior in the normal case of a sufficiently large buffer was
correct.

All known callers pass a sufficiently large buffer and have thus not
been affected by this issue. If a non-default value had been assigned
to this variable, the result was as documented, too.

Fix the function to fill the buffer with a partial result, if the
passed in buffer size is too low to hold the full result.

(cherry picked from commit e11ad014d1)

libc: add helper furnction to set sysctl() user.* variables

Testing had revealed that trying to retrieve the user.localbase
variable into to small a buffer would return the correct error code,
but would not fill the available buffer space with a partial result.

A partial result is of no use, but this is still a violation of the
documented behavior, which has been fixed in the previous commit to
this function.

I just checked the code for "user.cs_path" and found that it had the
same issue.

Instead of fixing the logic for each user.* sysctl string variable
individually, this commit adds a helper function set_user_str() that
implements the semantics specified in the sysctl() man page.

It is currently only used for "user.cs_path" and "user.localbase",
but it will offer a significant simplification when further such
variables will be added (as I intend to do).

(cherry picked from commit 9535d9f104)

sysctlbyname(): restore access to user variables

The optimization of sysctlbyname() in commit d05b53e0ba had the
side-effect of not going through the fix-up for the user.* variables
in the previously called sysctl() function.

This lead to 0 or an empty strings being returned by sysctlbyname()
for all user.* variables.

An alternate implementation would store the user variables in the
kernel during system start-up. That would allow to remove the fix-up
code in the C library that is currently required to provide the actual
values.

This update restores the previous code path for the user.* variables
and keeps the performance optimization intact for all other variables.

(cherry picked from commit af7d105379)
2022-03-04 20:54:00 +01:00
..
aarch64 Add sched_getcpu() 2022-01-14 18:17:29 +02:00
amd64 libc: add _get_tp() private function 2021-04-23 14:14:07 +03:00
arm Add sched_getcpu() 2022-01-14 18:17:29 +02:00
capability Fix a few mandoc issues 2020-10-09 19:12:44 +00:00
compat-43 Adjust history, info source from v1's manuals 2019-09-04 13:44:46 +00:00
db tools/build: Don't redefine open() for the linux bootstrap 2021-08-05 10:00:45 +01:00
gdtoa Remove sparc64 specific parts of libc. 2020-02-26 18:55:09 +00:00
gen libc: return partial sysctl() result if buffer is too small 2022-03-04 20:54:00 +01:00
gmon mcount: tidy up ANSIfication 2018-10-20 22:39:35 +00:00
i386 libc: add _get_tp() private function 2021-04-23 14:14:07 +03:00
iconv libc: Fix "harmless" iconv one-byte overread 2022-01-24 23:59:47 +00:00
include Add sched_getcpu() 2022-01-14 18:17:29 +02:00
inet libc: fix cases of undefined behavior. 2018-08-07 15:24:19 +00:00
isc SPDX: more ISC-related files. 2017-12-08 17:52:53 +00:00
locale lnumeric.c: replace some space*8 by tabs 2022-02-09 02:42:46 +02:00
md Replace dot-dot relative pathing with SRCTOP-relative paths where possible 2017-01-20 03:23:24 +00:00
mips Add sched_getcpu() 2022-01-14 18:17:29 +02:00
nameser Bounds check again after advancing cp, otherwise we have a possible 2019-09-05 19:35:30 +00:00
net libc: Fix build with -DNS_REREAD_CONF. 2021-12-31 19:26:43 -05:00
nls Implement strerror_l(). 2020-12-16 09:02:09 +00:00
posix1e acl_delete_entry(): remove write-only variable 2021-12-06 02:23:45 +02:00
powerpc Add sched_getcpu() 2022-01-14 18:17:29 +02:00
powerpc64 Add sched_getcpu() 2022-01-14 18:17:29 +02:00
powerpcspe [PowerPC] [PowerPCSPE] Fix multiple issues in fpsetmask(). 2021-03-08 12:39:33 -06:00
quad Add casts and L suffixes to libc quad support, to work around various 2020-02-17 20:14:59 +00:00
regex libc: regex: rework unsafe pointer arithmetic 2021-01-08 13:58:35 -06:00
resolv res_init: remove unused inet_makeaddr with IN_LOOPBACKNET 2021-12-10 10:26:14 -06:00
riscv Add sched_getcpu() 2022-01-14 18:17:29 +02:00
rpc libc clnt_com_create: relock rpcsoc_lock earlier when port is obtained from portmapper 2022-01-15 02:51:13 +02:00
secure libc: ssp: sprinkle around some __dead2 2021-10-06 02:14:42 -05:00
softfloat libc: use standard LF line endings, not CRLF 2022-02-08 15:52:23 -05:00
stdio fread.c: fix undefined behavior 2022-03-04 20:47:23 +01:00
stdlib qsort.c: prevent undefined behavior 2022-03-04 20:47:02 +01:00
stdtime strftime.3: Fix a typo and use St for standards 2022-02-14 18:05:07 +01:00
string libc: correct SPDX tag on strstr.c 2022-01-18 19:32:29 -05:00
sys libc binuptime(): use the right function to get the most significant bit index 2022-02-15 02:36:51 +02:00
tests sendfile_test: fix copy-paste bug 2022-03-02 15:56:31 -06:00
uuid uuid(3): Document return values 2021-11-21 19:43:31 -05:00
x86 Make CPU_SET macros compliant with other implementations 2022-01-14 18:17:30 +02:00
xdr typo: s/impelmentation/implementation/. 2020-02-07 15:14:29 +00:00
yp Increase the size of the send and receive buffers for YP client rpc 2019-09-16 06:42:01 +00:00
libc.ldscript
libc_nossp.ldscript Add different libc ldscript: the one without libssp -- 2016-10-12 13:19:21 +00:00
Makefile libc: Use the initial-exec TLS model 2021-09-14 08:50:53 -04:00
Makefile.depend Update Makefile.depend files 2019-12-11 17:37:53 +00:00
Makefile.depend.options Update libssp paths in various Makefile.depend* files 2020-01-06 18:15:55 +00:00
Versions.def Create namespace for the symbols added during 14-CURRENT cycle. 2021-07-22 13:33:10 +03:00