This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Hi, attached there is a patch to fix few issues in Hurd's getlogin_r(): avoid a static buffer, and check for buffer shorter than necessary. Thanks, -- Pino Toscano
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 <toscano.pino@tiscali.it>
* 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)
Attachment:
signature.asc
Description: This is a digitally signed message part.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |