LibC: Fix truncated strncpy() in getlogin()

This commit is contained in:
Andreas Kling 2020-04-13 11:58:00 +02:00
parent dda9ffe906
commit d1ffdea550
Notes: sideshowbarker 2024-07-19 07:38:08 +09:00

View file

@ -538,7 +538,7 @@ char* getlogin()
{
static char __getlogin_buffer[256];
if (auto* passwd = getpwuid(getuid())) {
strncpy(__getlogin_buffer, passwd->pw_name, sizeof(__getlogin_buffer));
strncpy(__getlogin_buffer, passwd->pw_name, sizeof(__getlogin_buffer) - 1);
endpwent();
return __getlogin_buffer;
}