From patchwork Mon Feb 5 13:27:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 869279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-89973-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="p58QSVjM"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zZpMy0hQfz9t3p for ; Tue, 6 Feb 2018 00:29:17 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=c2bjLKEuwvp3pPXWc1PbqiarwT5ePOK clbYpk20qPkPsGhAMMULAwsXwpPLnUP7ZgOdKRN0TsptRyxN7UvGvGYlTmWrIeU2 fjUtcEo+qZlgk9Hns01TZkM6HYGyqD/3xQE8gxbBAnAAZSt9JgEK+6qB4udGxWtq 9Z/5f9iRFIjc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=GD0ULpkQL0RpLE7rXZW4t9tzI4c=; b=p58QS VjMiPoqv7K1CHcwLwTMeaxBYcrXjf/z0MPK3cy7X2OZzFh8SR9waokNMAtTS8QEG GWZ6wATaiq+vSBLQb1Ts08BxlyQaAN3s9GRirWTNpRt6lyHmzUOuow3xzHyZg3eq m6zxmgBRFLy/TmFBg4cvr2OZ5A109kKa+84+AM= Received: (qmail 33718 invoked by alias); 5 Feb 2018 13:27:58 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 33567 invoked by uid 89); 5 Feb 2018 13:27:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f182.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pX1HWCiM7nk7eiqTgZ9r3GFmkrFlV+di1l00s9rLzk0=; b=hvOvB/jVhpmWzYLhWJSyIP6bHMtuQfuPvzYP8/4VAgpGHrezzSmzKWeXbdQ7G5Say8 IfQS/4sj0B4p00XubAT3kk9TS19LIxeoal1HP+2+DEmsWvQ6RT3VB8gRG+DR2bySlBnm PD8DooBuFd4SexYH/87jjl3qKpr6useFctXL5s9/cTj0o/z++7Sro/ZH+SiCAOpPLUph pVR8ulKgRY55A5k0JVRau+044URJpnHRpgYB1OmfPxoAPky4JK3gNGrvJUY37eZcIRni xUreci5VLufKRuEhn6RWP3iPAQPC8YLheVapdI20Kc9tXXsx3AAOqChEAFvFsqwUeDcw XSuQ== X-Gm-Message-State: APf1xPD+aXIHJsNueQ0eOb8C4GqnGG8bSXGy+tV4BFcW2nYaKaXvBn6a NeCkfl3+h/aPoanG9oJ90K9EaP6tlrY= X-Google-Smtp-Source: AH8x226V+F5lUqEqX/s/j9L6aYE3SLOF7elCgWS9uCSzII99cpH54pXDvN6wM6wIPjH0k53tMYZd+A== X-Received: by 10.200.56.17 with SMTP id q17mr8373745qtb.313.1517837274126; Mon, 05 Feb 2018 05:27:54 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v2 09/12] getlogin_r: switch Linux variant to struct scratch_buffer Date: Mon, 5 Feb 2018 11:27:31 -0200 Message-Id: <1517837254-19399-10-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1517837254-19399-1-git-send-email-adhemerval.zanella@linaro.org> References: <1517837254-19399-1-git-send-email-adhemerval.zanella@linaro.org> From: Florian Weimer [BZ #18023] * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Use scratch_buffer instead of extend_alloca. --- ChangeLog | 6 ++++++ sysdeps/unix/sysv/linux/getlogin_r.c | 34 +++++++++++++--------------------- 2 files changed, 19 insertions(+), 21 deletions(-) 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 #include #include +#include #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; }