From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4564 invoked from network); 21 Oct 2022 21:13:09 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 21 Oct 2022 21:13:09 -0000 Received: (qmail 9707 invoked by uid 550); 21 Oct 2022 21:13:05 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 9666 invoked from network); 21 Oct 2022 21:13:04 -0000 From: Ismael Luceno To: musl@lists.openwall.com Cc: Rich Felker , Ismael Luceno Date: Fri, 21 Oct 2022 23:12:50 +0200 Message-Id: <20221021211250.15590-1-ismael@iodev.co.uk> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam: Yes Subject: [musl] [RESEND PATCH] glob: implement GLOB_NOMAGIC Signed-off-by: Ismael Luceno --- include/glob.h | 1 + src/regex/glob.c | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/glob.h b/include/glob.h index 4a562a206d52..0ff70bdfeef2 100644 --- a/include/glob.h +++ b/include/glob.h @@ -31,6 +31,7 @@ void globfree(glob_t *); #define GLOB_NOESCAPE 0x40 #define GLOB_PERIOD 0x80 +#define GLOB_NOMAGIC 0x0800 #define GLOB_TILDE 0x1000 #define GLOB_TILDE_CHECK 0x4000 diff --git a/src/regex/glob.c b/src/regex/glob.c index 9de080ed9ccd..29215c79ce39 100644 --- a/src/regex/glob.c +++ b/src/regex/glob.c @@ -260,13 +260,20 @@ int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, i for (cnt=0, tail=head.next; tail; tail=tail->next, cnt++); if (!cnt) { - if (flags & GLOB_NOCHECK) { - tail = &head; - if (append(&tail, pat, strlen(pat), 0)) - return GLOB_NOSPACE; - cnt++; + size_t len; + /* GLOB_NOMAGIC implies GLOB_NOCHECK */ + if (flags & GLOB_NOMAGIC) { + len = strcspn(pat, "*?["); + } else if (flags & GLOB_NOCHECK) { + len = strcspn(pat, ""); } else return GLOB_NOMATCH; + if (pat[len]) + return GLOB_NOMATCH; + tail = &head; + if (append(&tail, pat, len, 0)) + return GLOB_NOSPACE; + cnt++; } if (flags & GLOB_APPEND) { -- 2.38.1