aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2010-05-05 09:44:50 -0700
committerUlrich Drepper <drepper@redhat.com>2010-05-05 09:44:50 -0700
commit5ae958d74180e2572d198bd7872c86f391de6da7 (patch)
tree72cdaca4eb866f52e07ebf77f7cf540789d4f958 /sysdeps
parent3155f066219acaa9e7f8b8a3737f336f98e978b9 (diff)
downloadglibc-5ae958d74180e2572d198bd7872c86f391de6da7.tar
glibc-5ae958d74180e2572d198bd7872c86f391de6da7.tar.gz
glibc-5ae958d74180e2572d198bd7872c86f391de6da7.tar.bz2
glibc-5ae958d74180e2572d198bd7872c86f391de6da7.zip
Handle too-small buffers in Linux getlogin_r.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/unix/sysv/linux/getlogin_r.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/sysdeps/unix/sysv/linux/getlogin_r.c b/sysdeps/unix/sysv/linux/getlogin_r.c
index d9c66fe259..dad2671e80 100644
--- a/sysdeps/unix/sysv/linux/getlogin_r.c
+++ b/sysdeps/unix/sysv/linux/getlogin_r.c
@@ -81,13 +81,22 @@ __getlogin_r_loginuid (name, namesize)
if (tpwd == NULL)
goto fail;
- strncpy (name, pwd.pw_name, namesize - 1);
- name[namesize - 1] = '\0';
-
+ int result = 0;
+ size_t needed = strlen (pwd.pw_name) + 1;
+ if (needed > namesize)
+ {
+ __set_errno (ERANGE);
+ result = ERANGE;
+ goto out;
+ }
+
+ memcpy (name, pwd.pw_name, needed);
+
+ out:
if (use_malloc)
free (buf);
- return 0;
+ return result;
}