소스 검색

cuserid: support invocation with a null pointer argument

this function was removed from the standard in 2001 but appeared in
SUSv2 with an obligation to support calls with a null pointer
argument, using a static buffer.
Sören Tempel 5 년 전
부모
커밋
ef137da642
1개의 변경된 파일2개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      src/legacy/cuserid.c

+ 2 - 0
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;
 }