mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH v2] cuserid: support invocation with a NULL pointer argument
@ 2020-01-29 11:20 Sören Tempel
  2020-01-29 11:59 ` Sören Tempel
  0 siblings, 1 reply; 5+ messages in thread
From: Sören Tempel @ 2020-01-29 11:20 UTC (permalink / raw)
  To: musl

I did not manage to find a copy of IEEE 1003.1-1988 (the last POSIX
version where cuserid was last standardized) the Single UNIX
specification version 2 does state the following though [1]:

	If s is a null pointer, this representation is generated in an
	area that may be static (and thus overwritten by subsequent
	calls to cuserid()), the address of which is returned.

Even though this a legacy function it would therefore be nice for musl
to support usage with a NULL pointer. I ran into this on Alpine Linux
when using cdparanoia [2] which uses cuserid like this and therefore
caused a crash on my system.

[1]: https://pubs.opengroup.org/onlinepubs/7908799/xsh/cuserid.html
[2]: https://xiph.org/paranoia/index.html
---
 src/legacy/cuserid.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/legacy/cuserid.c b/src/legacy/cuserid.c
index 4e78798d..fd7832e4 100644
--- a/src/legacy/cuserid.c
+++ b/src/legacy/cuserid.c
@@ -5,10 +5,12 @@
 
 char *cuserid(char *buf)
 {
+	static char usridbuf[L_cuserid];
 	struct passwd pw, *ppw;
 	long pwb[256];
 	if (getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw))
 		return 0;
+	if (!buf) buf = usridbuf;
 	snprintf(buf, L_cuserid, "%s", pw.pw_name);
 	return buf;
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-13 19:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-29 11:20 [musl] [PATCH v2] cuserid: support invocation with a NULL pointer argument Sören Tempel
2020-01-29 11:59 ` Sören Tempel
2020-03-22  9:51   ` Sören Tempel
2020-03-22 15:05     ` Rich Felker
2021-02-13 19:06       ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).