Fix #211: drop hard-coded getty limit of 32 characters for usernames

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-01-11 13:40:07 +01:00
parent 495c8c9eac
commit 950ca953f5
+15 -1
View File
@@ -25,6 +25,7 @@
#include <err.h>
#include <errno.h>
#include <limits.h> /* LOGIN_NAME_MAX */
#include <paths.h>
#include <signal.h>
#include <stdio.h>
@@ -33,6 +34,7 @@
#include <sys/utsname.h>
#include <sys/ttydefaults.h> /* Not included by default in musl libc */
#include <termios.h>
#include <unistd.h> /* sysconf() */
#include "finit.h"
#include "helpers.h"
@@ -42,6 +44,12 @@
#define _PATH_LOGIN "/bin/login"
#endif
#ifndef LOGIN_NAME_MIN
#define LOGIN_NAME_MIN 64
#endif
static long logname_len = 32; /* useradd(1) limit at 32 chars */
/*
* Read one character from stdin.
*/
@@ -197,7 +205,7 @@ static int do_login(char *name)
static int getty(char *tty, speed_t speed, char *term, char *user)
{
const char cln[] = "\r\e[K\n";
char name[33]; /* useradd(1) limit at 32 chars */
char name[logname_len + 1]; /* +1 for NUL termination */
pid_t sid;
/*
@@ -263,6 +271,12 @@ int main(int argc, char *argv[])
if (optind < argc)
term = argv[optind++];
logname_len = sysconf(_SC_LOGIN_NAME_MAX);
if (logname_len == -1i)
logname_len = LOGIN_NAME_MAX;
if (logname_len < LOGIN_NAME_MIN)
logname_len = LOGIN_NAME_MIN;
return getty(tty, atoi(speed), term, NULL);
}