From patchwork Thu Jun 8 21:13:23 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: 103413 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp2632717qgd; Thu, 8 Jun 2017 14:15:36 -0700 (PDT) X-Received: by 10.99.103.7 with SMTP id b7mr40191001pgc.2.1496956536368; Thu, 08 Jun 2017 14:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496956536; cv=none; d=google.com; s=arc-20160816; b=D5EN9RMAUTz7f+ooUFRsAnOYi67iEbay1cp1l+9EH5pmr/Hy6dLE6Pp457eX6sQtO6 wL+uyrqJ/25+c3O/9yllkgVvFkge8VoWiVN0jAK1cFCJk2fRNZlRPleZJ7HhGRtrrcnl 5WUrfArwHGKQdekVA7vTDKV87uIVMdcEAoubD68loZRWPQV8/Y6s0GrSe3B21AdC1NVj IBSANJycTgGmDYtMB0PSfnZVi+XlgCxYXG8QaLcCG9Zi/K+MkuNLczo/N0EfQbO3mMIF 4BijDlZe0Mt9KLYtWCMBZCxy7xxvCyA6I4OjCJlXI7OiMwhlnQ3T5uWodWoWBLSIyN2y Jymw== 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=WAaG+BIGQi8QXi6C1pzSbHUrOHLs5nok0Qy6oeJhEMQ=; b=fpuGoXBYEbLCBLswJniyUZQxV3J1qOM+ui7HJBeRFWwoiINabzmqmMpTp+mhALxzXD Wy6hEcKnoHSmlwt7WA2yx/H91S8RDO9cfW1riYhGcBOHce0H6pa17gfxGRqhUxmrAWXA I+PLoq2FNZGG4N1vjzMuDDmY+HMrN6iHlmJQXmQpM/9rcQX4G4Su790EldaeLlNGaLIJ fLNFSt9E/2h5EYZpeTRiJVJg1rHu6TQ54OhXxDqYrL3C3bibNkOlDFUvmI/IFZlB/a8z Tw9UoIKeKh+rYgSyU4ogxuRC/hiRmsnZDmsiCCAF0/WmmMT/zOO6ocUkevwiIAFvkQ8C V3dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-80207-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-80207-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 y81si5343583pfj.43.2017.06.08.14.15.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 14:15:36 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-80207-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; spf=pass (google.com: domain of libc-alpha-return-80207-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-80207-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=S8qQYxfz16NNkzgMPO8wsNNvopu5MB3 QcpevozYGnMUlxuC3S+nF4rZMEYlosK9l8/CcSfeZV1e6WssVJ9/B+8QZYTb2V0I +4rNIWO3FE2AGN3PiZLvnuLlezQ27ec2vgcjRxDgSOf6cB5n3zfjER9w68RoS+JZ 6JkRqV2QyIlg= 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=zpkJDErB/l9GARzKjAz7d45akGE=; b=cX3jp GELh9Uihoeta1rwJZxngKSh1/90BbM4FcM+QdNLkK5lmVT9vQJqkg6C575cJFIRn pV346HiIxSmYY+H2wnk61fIcLwaXvP5bGjQjd6WdnP4dW6o9//F/VIZE4r/05FH0 RkIoL/qCGOcWgTo7ElgUsM8vyTvFvZ3oyTZRUY= Received: (qmail 39323 invoked by alias); 8 Jun 2017 21:14:05 -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 39146 invoked by uid 89); 8 Jun 2017 21:14:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=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=accomplish X-HELO: mail-qt0-f181.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=WAaG+BIGQi8QXi6C1pzSbHUrOHLs5nok0Qy6oeJhEMQ=; b=cTTxCnpe094IoM6VNo3GEk8P3EGvWyDJc1En/Ciy4JnHbIc0NNTRK6UaCTnVZBuw8Q U/rcg2Qmo6z0F7PMxQwlR3zYLLnLnPeuUY9+q3QzNjTwELGqr0fjjW+DRpFXkbjAhKji p/YZxqNUkyRsCccArVfQDefJ7iLwhk629JHR5VJ1PIFM9c4IX2BNGkog7mII3l8O6oeb vmkTyr8jZr1qGfGnkBiPk09n3kimMB4dl6G+DYRgHE7GVIWFKYqjODk2pO2SBDKpkA7h 43GqANdmXYT4rjfTbX8aXijPdwMzg41ib3hzBJgHlXRHVg+ykLvSwCO83Y9IWNWeZ/31 7IGQ== X-Gm-Message-State: AKS2vOx9oOBgyzZxY5Z3wTWlCG/hj/TcBG8Niuw9ibScBuzVCXjZblvv 61HbGQuyeu14fiItuDUiaw== X-Received: by 10.55.95.5 with SMTP id t5mr46885253qkb.64.1496956445155; Thu, 08 Jun 2017 14:14:05 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 09/17] posix: Remove glob GET_LOGIN_NAME_MAX usage Date: Thu, 8 Jun 2017 18:13:23 -0300 Message-Id: <1496956411-25594-10-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1496956411-25594-1-git-send-email-adhemerval.zanella@linaro.org> References: <1496956411-25594-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 | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) -- 2.7.4 diff --git a/posix/glob.c b/posix/glob.c index fbb7aa7..14a502c 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -92,10 +92,8 @@ #include "glob_internal.h" #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; @@ -677,25 +675,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) - goto err_nospace; - 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; @@ -705,7 +687,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) { @@ -733,11 +715,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') {