From nobody Mon Jul 6 13:18:51 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gv4gc0RFVz6jX1H for ; Mon, 06 Jul 2026 13:18:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gv4gb6WYdz3q8L for ; Mon, 06 Jul 2026 13:18:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783343931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zS/fv17PzNVKS0f2ifoDNhlIe0w5QkoBgAdLeBikzLo=; b=K0VSyycPnj56LCp+oXr9/6U2yrk8lfG1XMADT2E51zAGryrBRRKxq95yLqdzW0bCgdXKwq MHIatxagjJx3SI3Y+ulqUkiCmiGPfSzcrhoigfi+kYH5R6JDV6E7cyA0pYZ7C+Lbu4obiT dIAE+YhwUWE9Y9mAz4XPE/nzqwWM/c1iODDdwgoRdl7j9glQKAQGU0eSexACX6LQN+i228 upcxI2Mm8TZdv2W5cHZHZt+sYqEItvzii7tjwq4hSU8vDn8+PZqZ5twDv1P6BDJw9ar4vE j78wSUBT2ia/QDJfcEIa5Qjm+5JoigQKG3ts5vxDaFjydaXz91+0SLWwM2AE5w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1783343932; a=rsa-sha256; cv=none; b=vcJ+QCtzSvmMtpssv6Qk0O3esmgA3LA5NTKwaAOcW7tlQjmUGWcyEu+0vgINTWQDXAkuDE pwy4ESiG7lG5oTQgy+0MB7SXOopW3jpx8TtgzKbWrYF3TazTCWxBDjsZauPYl1NnDCKoZN rFz3AiL+4x1gU3TMSA9X2BeUXRQbw4d4Wg8fevGkDVOtIbBIF3kWHvUYZ0UJUodwJ00fK0 hnGQYeWNzfSHNuLN7rTRPwoXdia9Ol/4TFMFIv+wZ0o1iIkpkyLw5Ku5+GZWYkKcoc/fuB QllSk8KsNQxBHlp1YEBB2VjM8JtsVvy9WkGhlMsq0jk6l2ji30MOzwrhpVTkag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783343932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zS/fv17PzNVKS0f2ifoDNhlIe0w5QkoBgAdLeBikzLo=; b=TmEtmyvUnikeu+mEG6FSHy++6R3i0I0vemyULQQJGbI7s/oeSnHa0XBPTYwcrOZ2BrHJOi 6KQF0+iSfS6xCzZ4+BaAddDf1HK9COoFTF3iv0f3+BbQz7rAZnNW5Bc7HdZI1E6an3DG3Z 7nb23BXztrh0xbpjuIlk/272nAIVehuwOfrh1YPJtfdDxdbgFy9tnvq5YEL7qNcdtDurry tw/pi4rSKP1r3a04dtL0Cq0kEDz7ZTPtA38r7j+CMf+6TYdo3Qpq4Ouu1TM7ZEHQ03Am/X b2Qtjo1I9Bq+7aq/vhVj5qPpe1nptPJ2QrEAd9zNR0jCO6TH+3YzOn0Cp5SKog== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gv4gb4kWKz15bZ for ; Mon, 06 Jul 2026 13:18:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3fbb2 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 06 Jul 2026 13:18:51 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 705a88a71727 - main - ee: Improve handling of malformed UTF-8 characters List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 705a88a717272c52c897c3d28dc2997980ee67f4 Auto-Submitted: auto-generated Date: Mon, 06 Jul 2026 13:18:51 +0000 Message-Id: <6a4bab3b.3fbb2.737b6ba9@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=705a88a717272c52c897c3d28dc2997980ee67f4 commit 705a88a717272c52c897c3d28dc2997980ee67f4 Author: Mark Johnston AuthorDate: 2026-07-06 13:16:32 +0000 Commit: Mark Johnston CommitDate: 2026-07-06 13:18:13 +0000 ee: Improve handling of malformed UTF-8 characters In delete(), when copying the deleted character to the d_char buffer, don't assume that it fits. utf8_prev() may return a sequence of more than 5 bytes. In insert_utf8(), fix the copy-up of the line. We extended the line by "len" bytes, so "temp" has to be repositioned accordingly. Compare with plain insert(). Use sizeof when copying to buffers instead of hard-coding buffer sizes. Don't dynamically allocate d_char, there is no need. Fixes: 62fba0054d9e ("ee: add unicode support") Reported by: Sayono Hiragi (overflow in delete()) Reviewed by: bapt MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D57996 --- contrib/ee/ee.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/contrib/ee/ee.c b/contrib/ee/ee.c index 13a554bf0146..94bb296bcd65 100644 --- a/contrib/ee/ee.c +++ b/contrib/ee/ee.c @@ -194,7 +194,7 @@ unsigned char *srch_2; /* pointer to next character of string */ unsigned char *srch_3; unsigned char *in_file_name = NULL; /* name of input file */ char *tmp_file; /* temporary file name */ -unsigned char *d_char; /* deleted character */ +unsigned char d_char[5]; /* deleted character */ unsigned char *d_word; /* deleted word */ unsigned char *d_line; /* deleted line */ char in_string[513]; /* buffer for reading a file */ @@ -598,7 +598,6 @@ main(int argc, char *argv[]) signal(SIGCHLD, SIG_DFL); signal(SIGSEGV, SIG_DFL); signal(SIGINT, edit_abort); - d_char = malloc(5); /* UTF-8 chars can be up to 4 bytes + NUL */ d_word = malloc(150); *d_word = '\0'; d_line = NULL; @@ -832,7 +831,6 @@ insert_utf8(const unsigned char *mb, int len) { int counter; unsigned char *temp; - unsigned char *temp2; int i; text_changes = TRUE; @@ -848,17 +846,18 @@ insert_utf8(const unsigned char *mb, int len) counter++; temp++; } - temp++; - while (point < temp) + temp += len; + while (point + len - 1 < temp) { + unsigned char *temp2; + temp2 = temp - len; *temp = *temp2; temp--; } /* copy all bytes of the UTF-8 character */ - for (i = 0; i < len; i++) - point[i] = mb[i]; + memmove(point, mb, len); /* display the character before advancing past it */ wclrtoeol(text_win); @@ -931,8 +930,10 @@ delete(int disp) scr_pos = scr_horz; if (in == 8) { - memcpy(d_char, point, del_width); - d_char[del_width] = '\0'; + size_t width = min(del_width, 4); + + memcpy(d_char, point, width); + d_char[width] = '\0'; } while (temp_pos <= curr_line->line_length) { @@ -2993,7 +2994,7 @@ del_word(void) if (d_word != NULL) free(d_word); d_word = malloc(curr_line->line_length); - memcpy(tmp_char, d_char, 5); + memcpy(tmp_char, d_char, sizeof(tmp_char)); d_word3 = point; d_word2 = d_word; tposit = position; @@ -3026,7 +3027,7 @@ del_word(void) curr_line->line_length -= difference; *d_word2 = '\0'; draw_line(scr_vert, scr_horz,point,position,curr_line->line_length); - memcpy(d_char, tmp_char, 5); + memcpy(d_char, tmp_char, sizeof(d_char)); text_changes = TRUE; formatted = FALSE; } @@ -4141,7 +4142,7 @@ Format(void) unsigned char *temp_dword; unsigned char temp_d_char[5]; - memcpy(temp_d_char, d_char, 5); + memcpy(temp_d_char, d_char, sizeof(temp_d_char)); /* | if observ_margins is not set, or the current line is blank, @@ -4336,7 +4337,7 @@ Format(void) case_sen = temp_case; free(srch_str); srch_str = tmp_srchstr; - memcpy(d_char, temp_d_char, 5); + memcpy(d_char, temp_d_char, sizeof(d_char)); auto_format = tmp_af; midscreen(scr_vert, point); @@ -4720,7 +4721,7 @@ Auto_Format(void) unsigned char temp_d_char[5]; unsigned char *tmp_d_line; - memcpy(temp_d_char, d_char, 5); + memcpy(temp_d_char, d_char, sizeof(temp_d_char)); /* | if observ_margins is not set, or the current line is blank, @@ -4946,7 +4947,7 @@ Auto_Format(void) case_sen = temp_case; free(srch_str); srch_str = tmp_srchstr; - memcpy(d_char, temp_d_char, 5); + memcpy(d_char, temp_d_char, sizeof(d_char)); auto_format = TRUE; dlt_line->line_length = tmp_d_line_length; d_line = tmp_d_line;