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 9373 invoked from network); 8 Oct 2023 21:48:01 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Oct 2023 21:48:01 -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:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=w2TvISAY6RhYczvu/SzGOHkGPm1F3Q5kg9aTASxBDSA=; b=TYWbqq9MEGRzgobq7dtuXqZV5S LFtFsVslxvVQMKR7mu0P1Ptn1DvzjcT41z5nkischw51ZLfXE8FHkHzQNkf114vsB5eAdVKu8m50X OHqBfE74nJ1N22VAFihhbWXx0vuj2fdDtqMG7KQbDbTWFpc1PPNwfgiSDCkWxeVRx1txzpkaVxDIt CcDGRsVw4VJTIzQbaqi/5ORZAsI+Ll4pgWNM8aZRndB7wDxj9DUtAQjSfVvkYtwsAvwtJnzC5aleM ZTOs67QCIKTdNPVS5JKwSXYFUvFgkd6V0tMkukWr2gez/EO+tU2iTsI/ZpkuPAXDk68p4CDgriYbW d6O3TWqw==; Received: by zero.zsh.org with local id 1qpbd2-0003BL-TP; Sun, 08 Oct 2023 21:48:00 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1qpbcV-0002sU-3y; Sun, 08 Oct 2023 21:47:27 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1qpbcT-000Dos-BM for zsh-workers@zsh.org; Sun, 08 Oct 2023 23:47:25 +0200 In-reply-to: <51326-1696644317.959346@Oqom.p2Z_.86FS> From: Oliver Kiddle References: <51326-1696644317.959346@Oqom.p2Z_.86FS> To: zsh-workers@zsh.org Subject: metafy() (was Re: $watch, log and Cyrillic usernames) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <53124.1696801645.1@hydra> Date: Sun, 08 Oct 2023 23:47:25 +0200 Message-ID: <53125-1696801645.349232@KWzA.NFGU.Vwsy> X-Seq: 52214 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: I wrote: > However, in looking closer at the code I observed the existing use of > sizeof(u->ut_name) which is 32 on my system. So I tried creating 32 and > 33 character usernames (which, incidentally, useradd was happy with) and It occurred to be to double check what metafy() does about null termination with META_USEHEAP. The comment by META_USEHEAP is "get memory from the heap. This leaves buf unchanged". The main way it differs from META_HEAPDUP is that if no characters that need metafying are found, it will return back the original passed buf. However, it does add a terminating null at the len + 1 position so while the buf pointer is unchanged, what it points to does get changed. There aren't especially many calls to metafy with META_USEHEAP and in most cases, the call uses the result of getkeystring(). I noticed one case where we do need to add 1 byte to an allocation to accomodate this null. I'm not sure what the best approach is for the watch module. Subtracting 1 from n in each call to strnlen() avoids writing a null past the end of the buffer but is not ideal for 32 character usernames. Using META_HEAPDUP instead means a lot of heap allocations in the normal case where there are only short ASCII-only usernames. Any ideas? Oliver diff --git a/Src/subst.c b/Src/subst.c index cdbfc138a..60d850feb 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -1506,7 +1506,7 @@ substevalchar(char *ptr) } #ifdef MULTIBYTE_SUPPORT else if (isset(MULTIBYTE) && ires > 127) { - ptr = zhalloc(MB_CUR_MAX); + ptr = zhalloc(MB_CUR_MAX+1); len = ucs4tomb((unsigned int)ires & 0xffffffff, ptr); } if (len <= 0)