Browse Source

libc: getlogin should not query fd directly

K. Lange 3 years ago
parent
commit
0762fb30ce
1 changed files with 4 additions and 1 deletions
  1. 4 1
      libc/unistd/getlogin.c

+ 4 - 1
libc/unistd/getlogin.c

@@ -20,9 +20,12 @@ char * getlogin(void) {
 		}
 	}
 
+	char * name = ttyname(tty);
+	if (!name) return NULL;
+
 	/* Get the owner */
 	struct stat statbuf;
-	fstat(tty, &statbuf);
+	stat(name, &statbuf);
 
 	struct passwd * passwd = getpwuid(statbuf.st_uid);