From owner-svn-src-head@freebsd.org Mon Jul 18 18:24:32 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9BF5FB9DA83; Mon, 18 Jul 2016 18:24:32 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4BB9F1350; Mon, 18 Jul 2016 18:24:32 +0000 (UTC) (envelope-from ache@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u6IIOVvt065409; Mon, 18 Jul 2016 18:24:31 GMT (envelope-from ache@FreeBSD.org) Received: (from ache@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6IIOVNn065407; Mon, 18 Jul 2016 18:24:31 GMT (envelope-from ache@FreeBSD.org) Message-Id: <201607181824.u6IIOVNn065407@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ache set sender to ache@FreeBSD.org using -f From: "Andrey A. Chernov" Date: Mon, 18 Jul 2016 18:24:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r303010 - head/lib/libc/gen X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jul 2016 18:24:32 -0000 Author: ache Date: Mon Jul 18 18:24:31 2016 New Revision: 303010 URL: https://svnweb.freebsd.org/changeset/base/303010 Log: 1) Add all characters from ~ expansion as protected to be not interpreted as pattern meta chars. 2) GLOB_ERR and gl_errfunc are supposed to work only for real directories per POSIX, so don't act on missing or plain files, for ENOENT or ENOTDIR (as TODO in the code suggested). 3) Remove the hack in the manpage describing how to skip ENOENT and ENOTDIR in gl_errfunc, it is unneeded now. 4) Set errno to ENAMETOOLONG if g_Ctoc() expansion fails in g_opendir(), as in other places in the code which are wrappers around system functions. Modified: head/lib/libc/gen/glob.3 head/lib/libc/gen/glob.c Modified: head/lib/libc/gen/glob.3 ============================================================================== --- head/lib/libc/gen/glob.3 Mon Jul 18 16:58:47 2016 (r303009) +++ head/lib/libc/gen/glob.3 Mon Jul 18 18:24:31 2016 (r303010) @@ -275,24 +275,10 @@ is .Pf non- Dv NULL , .Fn glob calls -.Fa \*(lp*errfunc\*(rp Ns ( Fa path , errno ) . -This may be unintuitive: a pattern like -.Ql */Makefile -will try to -.Xr stat 2 -.Ql foo/Makefile -even if -.Ql foo -is not a directory, resulting in a -call to -.Fa errfunc . -The error routine can suppress this action by testing for -.Er ENOENT -and -.Er ENOTDIR ; +.Fa \*(lp*errfunc\*(rp Ns ( Fa path , errno ) , however, the .Dv GLOB_ERR -flag will still cause an immediate +flag will cause an immediate return when this happens. .Pp If Modified: head/lib/libc/gen/glob.c ============================================================================== --- head/lib/libc/gen/glob.c Mon Jul 18 16:58:47 2016 (r303009) +++ head/lib/libc/gen/glob.c Mon Jul 18 18:24:31 2016 (r303010) @@ -478,7 +478,7 @@ globtilde(const Char *pattern, Char *pat return (NULL); dc = wbuf; - for (b = patbuf; b < eb && *dc != EOS; *b++ = *dc++) + for (b = patbuf; b < eb && *dc != EOS; *b++ = *dc++ | M_PROTECT) continue; if (*dc != EOS) return (NULL); @@ -712,7 +712,8 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend = EOS; if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { - /* TODO: don't call for ENOENT or ENOTDIR? */ + if (errno == ENOENT || errno == ENOTDIR) + return (0); if (pglob->gl_flags & GLOB_ERR) return (GLOB_ABORTED); if (pglob->gl_errfunc) { @@ -937,8 +938,10 @@ g_opendir(Char *str, glob_t *pglob) if (*str == EOS) strcpy(buf, "."); else { - if (g_Ctoc(str, buf, sizeof(buf))) + if (g_Ctoc(str, buf, sizeof(buf))) { + errno = ENAMETOOLONG; return (NULL); + } } if (pglob->gl_flags & GLOB_ALTDIRFUNC)