This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch master updated. glibc-2.27.9000-34-g6d7aa2b
- From: azanella at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 6 Feb 2018 11:32:19 -0000
- Subject: GNU C Library master sources branch master updated. glibc-2.27.9000-34-g6d7aa2b
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, master has been updated
via 6d7aa2b531088c3a277911534179975eb2622954 (commit)
from 71aa429b029fdb6f9e65d44050388b51eca460d6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=6d7aa2b531088c3a277911534179975eb2622954
commit 6d7aa2b531088c3a277911534179975eb2622954
Author: Florian Weimer <fweimer@redhat.com>
Date: Wed Jan 24 15:40:29 2018 -0200
getlogin_r: switch Linux variant to struct scratch_buffer
[BZ #18023]
* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
Use scratch_buffer instead of extend_alloca.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
diff --git a/ChangeLog b/ChangeLog
index e6e29b1..a30eeea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-02-06 Florian Weimer <fweimer@redhat.com>
+
+ [BZ #18023]
+ * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
+ Use scratch_buffer instead of extend_alloca.
+
2018-02-06 Zack Weinberg <zackw@panix.com>
* libio/stdio.h: Don't define getc or putc as macros.
diff --git a/sysdeps/unix/sysv/linux/getlogin_r.c b/sysdeps/unix/sysv/linux/getlogin_r.c
index 84c51d0..73ea14c 100644
--- a/sysdeps/unix/sysv/linux/getlogin_r.c
+++ b/sysdeps/unix/sysv/linux/getlogin_r.c
@@ -18,6 +18,7 @@
#include <pwd.h>
#include <unistd.h>
#include <not-cancel.h>
+#include <scratch_buffer.h>
#define STATIC static
static int getlogin_r_fd0 (char *name, size_t namesize);
@@ -54,29 +55,22 @@ __getlogin_r_loginuid (char *name, size_t namesize)
endp == uidbuf || *endp != '\0'))
return -1;
- size_t buflen = 1024;
- char *buf = alloca (buflen);
- bool use_malloc = false;
struct passwd pwd;
struct passwd *tpwd;
int result = 0;
int res;
+ struct scratch_buffer tmpbuf;
+ scratch_buffer_init (&tmpbuf);
- while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) == ERANGE)
- if (__libc_use_alloca (2 * buflen))
- buf = extend_alloca (buf, buflen, 2 * buflen);
- else
- {
- buflen *= 2;
- char *newp = realloc (use_malloc ? buf : NULL, buflen);
- if (newp == NULL)
- {
- result = ENOMEM;
- goto out;
- }
- buf = newp;
- use_malloc = true;
- }
+ while ((res = __getpwuid_r (uid, &pwd,
+ tmpbuf.data, tmpbuf.length, &tpwd)) == ERANGE)
+ {
+ if (!scratch_buffer_grow (&tmpbuf))
+ {
+ result = ENOMEM;
+ goto out;
+ }
+ }
if (res != 0 || tpwd == NULL)
{
@@ -95,9 +89,7 @@ __getlogin_r_loginuid (char *name, size_t namesize)
memcpy (name, pwd.pw_name, needed);
out:
- if (use_malloc)
- free (buf);
-
+ scratch_buffer_free (&tmpbuf);
return result;
}
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 6 ++++++
sysdeps/unix/sysv/linux/getlogin_r.c | 34 +++++++++++++---------------------
2 files changed, 19 insertions(+), 21 deletions(-)
hooks/post-receive
--
GNU C Library master sources