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=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32344 invoked from network); 10 Oct 2023 21:46:57 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Oct 2023 21:46:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=V31imZwZVW3ITTOyDhH5v3vVlnG4B5AyElKnL8ikfZg=; b=WvEfLSNlz6SCzwEN6CJl0ThkUp 5zYTnMtkEWv+3GgB2M/sgPmIwt3omFHRkeTXYGpnqUYvBVcZHZvIu2Wj0u2ki9Yz/EJLWLzaL/OPV VeZNX9t6fyBlZhUjrHExzt/s7TotYtfi6dBebLFe5lhk6ptVYUfNp0A5ic1OzeNF9cEupWift+9j9 Wgon9KSerIsI6O3wiu8S475b2SaxYyFv7lB0p25QOM+9FPthMteD8KNoqqJ+3DBRPsU5Je08/jB8k XvPNrVDel1gDOlhwzpCGg18qZ9+rie9jyvp6t00pbTAil4WG8slb3BKgsgdBi4Vxonu9EAgqPaVch +9p6TIYA==; Received: by zero.zsh.org with local id 1qqKZ7-0003lg-5D; Tue, 10 Oct 2023 21:46:57 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1qqKYU-0003Sf-DX; Tue, 10 Oct 2023 21:46:19 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1qqKYR-00061F-NZ; Tue, 10 Oct 2023 23:46:15 +0200 cc: zsh-workers@zsh.org In-reply-to: From: Oliver Kiddle References: <51326-1696644317.959346@Oqom.p2Z_.86FS> <53125-1696801645.349232@KWzA.NFGU.Vwsy> To: Bart Schaefer Subject: Re: metafy() (was Re: $watch, log and Cyrillic usernames) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23138.1696974375.1@hydra> Date: Tue, 10 Oct 2023 23:46:15 +0200 Message-ID: <23139-1696974375.248113@yyVG.3uJG.H2TU> X-Seq: 52216 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Bart Schaefer wrote: > Handle the special case explicitly? If I follow your explanation, > something like this? Thanks. That works. Full patch follows. Oliver diff --git a/Src/Modules/watch.c b/Src/Modules/watch.c index 0de8cbf9a..97d4fa608 100644 --- a/Src/Modules/watch.c +++ b/Src/Modules/watch.c @@ -423,20 +423,23 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt, int prnt, int fini) /* See if the watch entry matches */ static int -watchlog_match(char *teststr, char *actual, int len) +watchlog_match(char *teststr, char *actual, size_t buflen) { int ret = 0; Patprog pprog; char *str = dupstring(teststr); + int len = strnlen(actual, buflen); + char *user = metafy(actual, len, + len == buflen ? META_HEAPDUP : META_USEHEAP); tokenize(str); if ((pprog = patcompile(str, PAT_STATIC, 0))) { queue_signals(); - if (pattry(pprog, actual)) + if (pattry(pprog, user)) ret = 1; unqueue_signals(); - } else if (!strncmp(actual, teststr, len)) + } else if (!strcmp(user, teststr)) ret = 1; return ret; } @@ -456,10 +459,17 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt) (void)watchlog2(inout, u, fmt, 1, 0); return; } - if (*w && !strcmp(*w, "notme") && - strncmp(u->ut_name, get_username(), sizeof(u->ut_name))) { - (void)watchlog2(inout, u, fmt, 1, 0); - return; + if (*w && !strcmp(*w, "notme")) { + int len = strnlen(u->ut_name, sizeof(u->ut_name)); + char *username = metafy(u->ut_name, len, + (len == sizeof(u->ut_name) ? + META_HEAPDUP /* allow for nul terminator */ : + META_USEHEAP)); + if (strcmp(username, get_username())) { + (void)watchlog2(inout, u, fmt, 1, 0); + return; + } + w++; } for (; *w; w++) { bad = 0; @@ -488,7 +498,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt) for (vv = ++v; *vv && *vv != '%'; vv++); sav = *vv; *vv = '\0'; - if (!watchlog_match(v, u->ut_host, strlen(v))) + if (!watchlog_match(v, u->ut_host, sizeof(u->ut_host))) bad = 1; *vv = sav; v = vv;