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: 126884 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1972122ljc; Mon, 5 Feb 2018 05:29:21 -0800 (PST) X-Google-Smtp-Source: AH8x226MKkXcRJPdL23redf8I8QsQjUJ6PfB7Otfaw8rmupu2mZheKMN2E79QyrT6JSgYkts3L8V X-Received: by 2002:a17:902:ab8d:: with SMTP id f13-v6mr9949554plr.215.1517837361207; Mon, 05 Feb 2018 05:29:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517837361; cv=none; d=google.com; s=arc-20160816; b=rYo+1p2WvilvVoBtqvWrJVg95+Mh5UP0gkNbetrASTuYhXpES+L5wZVGfU06jYR0OI MluPDjTi2ffCmnupHu+eyY69RkkwStQMifcW7YkhbZCnxhObNpb8zv5KiT2KmHj0sVR8 w5A/c1wFas+ri91DHIMGvC85HwdJIAXG64gRSeI/LMQit2ZL/r+sxqyAV7ahtV9yBeFI vwj3jH5YZ7lRJeOZ7o4uQ0AcfwBVwiYSpfj9cyT9A5FZuTv7vjWp4V9lwjYDCSyJ8Ny6 r74xTlsW2KiJ5N6hgeKXVnFmdvycKLQzOyF3zs+DAYscjhsfj7h0HKK6/zXswTpi4f5Y B26g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :delivered-to:sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=pX1HWCiM7nk7eiqTgZ9r3GFmkrFlV+di1l00s9rLzk0=; b=Hs6/KNwRqhxJ0o0InwlcksFvCLMVJ+xZe5McSakL7cNP3ZUFC0/DNgA4kgFYxufOP6 9CD9UI2DsutU/MhhfmHtLcXsf0WY291cjnnrM37wphQ1A8CxUDfapH9cHijtVHgKWuSZ yjrRqXxLksULD9jIOJB3d6eK6ylEzxoL7yebe41TfJCeGyTrMa4N9YpUDLPGohzB5MgH eQVDaq90TU6CsN57mGbQO14o7jYr7kL1kbkZCRz2Lotg1rcV9CalQjFIp8pV3TbLdORZ biny03Vp6SMDexgOu4zMektYy3Y6I0nrGUmh0YM8CGBpiPldQckiRZV9VI0/q9Ajib5h 0geQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=EGC20uHk; spf=pass (google.com: domain of libc-alpha-return-89973-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89973-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id o3-v6si5052402pls.450.2018.02.05.05.29.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 05:29:21 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-89973-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=EGC20uHk; spf=pass (google.com: domain of libc-alpha-return-89973-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89973-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=eNB52n3zyQY/FNUQxP6UK/KsZk2r3bA eSnHUmszYGK3IR2tTLrATXV06bZxiFXnalHxazHKy2z0DLokodcbnqozP44wV4Mc hCLDrYd0i3NQ69OdtJxhA8YJGz4d7uzpQuIW20g0WHmdzpMtCb8fP+6nZLLXUpxP X+Lnk15FGENw= 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=EGC20 uHkvatNOfvwvWdnHyZf/KJP12dcA+ZqaZqwfBF3lucMeTInCHN2/5hgMmNpNHrNt qQ76ei3VxFBiDpk/Fvw8hqLJ4IY0b59tVAK0lCdUZbRyPf+nj4HUQ8P/wi+rUcnS 30mNymBGU+LGqA0rrHETOGVBwdaN3ODY8zPbzQ= 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-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(-) -- 2.7.4 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; }