diff --git a/src/getty.c b/src/getty.c index 3b0abb88..5a12c00f 100644 --- a/src/getty.c +++ b/src/getty.c @@ -25,6 +25,7 @@ #include #include +#include /* LOGIN_NAME_MAX */ #include #include #include @@ -33,6 +34,7 @@ #include #include /* Not included by default in musl libc */ #include +#include /* 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); }