Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200128194032.4370-1-soeren+git@soeren-tempel.net>
Date: Tue, 28 Jan 2020 20:40:32 +0100
From: Sören Tempel <soeren+git@...ren-tempel.net>
To: musl@...ts.openwall.com
Subject: [PATCH] cuserid: support invocation with a NULL pointer argument

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..19206ba4 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;
+	buf = (buf) ? buf : usridbuf;
 	snprintf(buf, L_cuserid, "%s", pw.pw_name);
 	return buf;
 }

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.