hurd: compliance fixes for getlogin_r * do not make `login' static, as it would make getlogin_r no more reentrant; change its type to string_t. * fail with ERANGE if the `name' buffer has not enough space for the actual login string * copy with memcpy only the chars of the string 2012-04-28 Pino Toscano * sysdeps/mach/hurd/getlogin_r.c: Make LOGIN static and as string_t. Return -1 and set ERANGE if NAME is not big enough. --- a/sysdeps/mach/hurd/getlogin_r.c +++ b/sysdeps/mach/hurd/getlogin_r.c @@ -30,13 +30,21 @@ char *name; size_t name_len; { - static char login[1024]; /* XXX */ + string_t login; error_t err; + size_t len; if (err = __USEPORT (PROC, __proc_getlogin (port, login))) return errno = err; - strncpy (name, login, name_len); + len = __strnlen (login, sizeof login - 1) + 1; + if (len > name_len) + { + errno = ERANGE; + return errno; + } + + memcpy (name, login, len); return 0; } libc_hidden_def (getlogin_r)