![]() |
|
Message-ID: <41a157af-0e53-4ce9-8728-d47930a489e0@gnu.org> Date: Mon, 17 Feb 2025 16:05:17 +0100 From: Evgeny Grin <karlson2k@....org> To: Rich Felker <dalias@...c.org>, Alejandro Colomar <alx@...nel.org> Cc: libc-help@...rceware.org, linux-man@...r.kernel.org, Tobias Stoeckmann <tobias@...eckmann.org>, Serge Hallyn <serge@...lyn.com>, Iker Pedrosa <ipedrosa@...hat.com>, musl@...ts.openwall.com Subject: Re: Re: [shadow-maint/shadow] Add cheap defense mechanisms (PR #1171) Hi, 17-Feb-2025 15:44 (UTC+0100), Rich Felker wrote: > On Mon, Feb 17, 2025 at 10:42:06AM +0100, Alejandro Colomar wrote: > >>> Isn't it safe to use constructs like >>> ``` C >>> shadow = fopen (SGROUP_FILE, "re"); >>> if (NULL == shadow ) >>> shadow = fopen (SGROUP_FILE, "r"); >>> ``` >>> ? > > Unfortunately this doesn't work because it's UB to pass any modes but > the standards-specified ones. You are right, according to POSIX, failure with EINVAL is not guaranteed. That is not nice as the function is allowed to perform not as requested without any indication. > In any case use of fopen is just gratuitously bad for software that > targets POSIX. The right way to do things is a two-step open+fdopen. > This avoids needing to depend on new features to open and lets you use > all the modern open flags, openat if needed, etc. I agree. This would be the best approach. While dietlibc does not support "e" mode and glibc, musl, uclibc-ng support "e" mode, checking for particular library is bad. Checking for feature support is not reliable (function may not return error, while the flag is ignored or even used differently) and not possible when cross-compiling. -- Best, Evgeny Download attachment "OpenPGP_0x3193C1B46AE02A8E.asc" of type "application/pgp-keys" (3164 bytes) Download attachment "OpenPGP_signature.asc" of type "application/pgp-signature" (841 bytes)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.