hurd: compliance fixes for getlogin_r * do not make `login' static, as it would make getlogin_r no more reentrant * fail with ERANGE if the `name' buffer has not enough space for the actual login string * make sure to copy with strncpy only the chars of the string 2012-04-27 Pino Toscano * sysdeps/mach/hurd/getlogin_r.c (getlogin_r): Do not make `login' static. 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 @@ -29,13 +29,22 @@ getlogin_r (name, name_len) char *name; size_t name_len; { - static char login[1024]; /* XXX */ + char login[1024]; /* XXX */ error_t err; + size_t len; + login[0] = '\0'; if (err = __USEPORT (PROC, __proc_getlogin (port, login))) return errno = err; - strncpy (name, login, name_len); + len = strlen (login) + 1; + if (len > name_len) + { + errno = ERANGE; + return errno; + } + + strncpy (name, login, len); return 0; } libc_hidden_def (getlogin_r)