From patchwork Fri Aug 11 14:50:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 109885 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp975190obb; Fri, 11 Aug 2017 07:51:48 -0700 (PDT) X-Received: by 10.99.6.209 with SMTP id 200mr15213681pgg.227.1502463108223; Fri, 11 Aug 2017 07:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502463108; cv=none; d=google.com; s=arc-20160816; b=n8QRWfNLVvqo18Le533L/NA91IAsr/HOi3JR/NA3Odva6xUcZhpCTGLFkVTD9H7Rwg 3zeK1GwS0gbIitjjPD+U3Y9jiqX3GOL42K6RvNPdnA4Ntw3lki7RQlPESv9rgrUXIZLz HwWkQ4c+ZAN4/M8INgc+gWH/iY/gfea83QBI0vOx4Zref7PSgIN6C3CPlUzAbTj9AiGt brAPkcqa69gOYeorbK+HTKkHuXrZwCrt0IS0e+jSClk1mCwlAzgdeGHZOijCQhQgreEN L2uGAb1qgQnIpghCxBiFuCnXe8YXgTsFndlq2oq1XrH3wZoTEMQHvjgdbthbuTTLTJCC w9jw== 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: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=ejDV3Upzmc9p7raIFuHDLq9gjpGVSNTInk/V8ZxOMF0=; b=IILYz+bQeoMavxn93m6l1SgrOFuBl9IO8YJmmOoxMAxIZ+X/G7dfffZFFFrUkfpE0z /QccCQ6Met4NX3Gbdlw6Dq+XlGdbAMYIRoiYB3H9yLb/j82EbewwCzAzxP33xr1Jlf9G YituuVIG/JmBf8yTLS/EC1b7Lth3joQlS/BlvdYWQQ1nIN0cHbiWIY7D24tOHe/bFw21 Wi+qUL5FbrlRRb4EmU6iMIrmZm+W1CL4I3S7iwTAgHkBjuh7BwOtDvfRwXDukMObKOvS vSeeAMjT3KaOS7NZpMiad7rrGHJ7Naaj/L2cI2Pcih/S04WVWAOccW6csi7Rts+8dBf5 /jxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=kL+OpwGT; spf=pass (google.com: domain of libc-alpha-return-83028-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-83028-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 c32si633518plj.478.2017.08.11.07.51.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Aug 2017 07:51:48 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-83028-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=kL+OpwGT; spf=pass (google.com: domain of libc-alpha-return-83028-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-83028-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:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=VaoRvFRL0oDpyDpn6KngqL5oTPGO97c 9XtMDHKKXxxyxRPvQkyt4EY8+hbqs64oc7vjq/QjWESJcNX79pT6aTvHvAe6DAxJ zec3Y+Ab4LQENcp9aq0lXsxuVGpX3K7QeJiQfvUM0J8EIe4uMvsVAyvdRT0sE1qd v11ltEcnzuUQ= 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:subject:date:message-id:in-reply-to :references; s=default; bh=R9crkz0VxYOv5iL8izZPPPNgUwg=; b=kL+Op wGTiyr72RjYpGE1tgjB5PlRhMWUcDkHOLvwOr7+lyAy/FNGAywizKLDOsIHDeISi x2qiWAtgbPBdAJSGEolNWUYvUtwWvsrYtlquTyYMqWdAv+8uE332aLs2oEtSSMFM 8M/EOSVMsPxO/+OV8mqJ11LKE1lIKBJKSxwVFg= Received: (qmail 71437 invoked by alias); 11 Aug 2017 14:51:02 -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 71166 invoked by uid 89); 11 Aug 2017 14:51:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=accomplish X-HELO: mail-qk0-f180.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:subject:date:message-id:in-reply-to :references; bh=ejDV3Upzmc9p7raIFuHDLq9gjpGVSNTInk/V8ZxOMF0=; b=JjsnpW8+K3TmENHAdFXP2wa9NjO04xjpwFPSm5j2npPyaCkTdlr2DM16Jp9r/Migxf 6q9RM+OJpaZkso+OQcjUdXXySNvyVU80RE56xL1tM4sv3JWbCCHoI5dxcXqHmqzLMkul zPUE0yb9S8lE1iE9pi14oe4bi5xhKr00+ninXpeobIWyZ+P1UI7RQYSabC6HriQyxwXU 4w4TITrr/qk6t/T+UGY/d7/UyirM1XUcwDa+aofDeGC73MxS/av/D1EGggv/8l72CdOK cjb4/tZlKujDnKWVgpVuoIicjlsQWefbBNGFKtMJIUlGY6bAqxfRy4p6uMB09HV4sAm5 xdqg== X-Gm-Message-State: AHYfb5iTuPb2qUJV7NO3TJp2zmCw8IxLrAa1leZZiZ4lDlDa4soJA5sJ 6c3cz2fDglBVUVgrl0mbaQ== X-Received: by 10.55.7.7 with SMTP id 7mr20219209qkh.121.1502463058233; Fri, 11 Aug 2017 07:50:58 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 06/18] posix: Remove glob GET_LOGIN_NAME_MAX usage Date: Fri, 11 Aug 2017 11:50:32 -0300 Message-Id: <1502463044-4042-7-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1502463044-4042-1-git-send-email-adhemerval.zanella@linaro.org> References: <1502463044-4042-1-git-send-email-adhemerval.zanella@linaro.org> Current glob implementation allows non limited user name for home directory construction on GLOB_TILDE case. To accomplish it glob either construct a name on stack if size are small enough (based on current alloca_used) value in heap otherwise. There is no actual login to resize the buffer in case of the resizing the buffer in case of ERANGE, so a static buffer using glibc default LOGIN_NAME_MAX is suffice. Checked on x86_64-linux-gnu. * posix/glob.c (LOGIN_NAME_MAX): Define if not defined. (glob): Use static buffer for user_name on getlogin_r. --- posix/glob.c | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) -- 2.7.4 diff --git a/posix/glob.c b/posix/glob.c index 99e9c54..3a74758 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -91,10 +91,8 @@ #include #include -#ifdef _SC_LOGIN_NAME_MAX -# define GET_LOGIN_NAME_MAX() sysconf (_SC_LOGIN_NAME_MAX) -#else -# define GET_LOGIN_NAME_MAX() (-1) +#ifndef LOGIN_NAME_MAX +# define LOGIN_NAME_MAX 256 #endif static const char *next_brace_sub (const char *begin, int flags) __THROWNL; @@ -667,28 +665,9 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), if (home_dir == NULL || home_dir[0] == '\0') { int success; - char *name; - int malloc_name = 0; - size_t buflen = GET_LOGIN_NAME_MAX () + 1; - - if (buflen == 0) - /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try - a moderate value. */ - buflen = 20; - if (glob_use_alloca (alloca_used, buflen)) - name = alloca_account (buflen, alloca_used); - else - { - name = malloc (buflen); - if (name == NULL) - { - retval = GLOB_NOSPACE; - goto out; - } - malloc_name = 1; - } + char user_name[LOGIN_NAME_MAX]; - success = __getlogin_r (name, buflen) == 0; + success = __getlogin_r (user_name, sizeof (user_name)) == 0; if (success) { struct passwd *p; @@ -698,7 +677,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), struct scratch_buffer pwtmpbuf; scratch_buffer_init (&pwtmpbuf); - while (getpwnam_r (name, &pwbuf, + while (getpwnam_r (user_name, &pwbuf, pwtmpbuf.data, pwtmpbuf.length, &p) != 0) { @@ -730,11 +709,6 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int), } scratch_buffer_free (&pwtmpbuf); } - else - { - if (__glibc_unlikely (malloc_name)) - free (name); - } } if (home_dir == NULL || home_dir[0] == '\0') {