From nobody Wed Nov 27 18:20:27 2024 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 4Xz7641H8dz5fZrQ; Wed, 27 Nov 2024 18:20:28 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xz7640XHzz44G0; Wed, 27 Nov 2024 18:20:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732731628; 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=RLcu70Q1CoL9gqGjP3chJutDLZJbKZG18MAGgkEczSQ=; b=aG+CZJRORJRy62iFt/0uc3+b18goMxKZdWolGLHTPUAG54jOA65zuaF5Wb7t6sGuT8HLDg +4ZDFZpQUE7PCd+ew6CgDGqf1PQRb577pieDPzmexVI1RPW4S4/k16n3Sw/J9CrWJjS/Bs uk9Lb8c43FGrAHU0sNKlsDvL97+agcZNQWRB0GT7SxXkVLApk/SpEuP+5T66LKzYa01GhK ny8uvZcv5EPqSDN7wpTPhr79h91960fjkq0cZN6aNB9n3wP0lZCYrkU9KmEMXwmwfjmymD KkmuCreL13cnGCb9NLo6wYD3BXLwfKlgvyBNEglwOQ6hz+wDrKMDfSfsGEYSoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732731628; 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=RLcu70Q1CoL9gqGjP3chJutDLZJbKZG18MAGgkEczSQ=; b=vGTFJqUN62b3EgHbMrln/VpHqkwrKLIHUaiAQ17DdzJJqg/6tHtK2ivE59yvd3xkBrtfZj fkKuSGaM0ncy2L3A9KyrG0jVJ3sLwzThr3LI+kSYKpMRll9rsyh0LCMiQgZt+eR0B4SLmu 0la5CJFRugRe6NNkfhz2KUnRQBAMpLMkXmaScGVDXyCAuAaupeubupvigtawvkKOTLNgMC JtlHDDlsHk0SnMBeU1ce+mtNMDrvVBZNJLrhqvwvk0ncPVsk2c7dq502tlTq6u7BGaVjo/ YTHR1dTNK9Zfu5IgSYf/9CHIF747WdejXxLf+AFWZmR7zWel7yUAKJ7Ysdgeaw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732731628; a=rsa-sha256; cv=none; b=HfsxIP/AhZd2W/QgmmM+55MrC5BHq353jM7sKCuLSdnzVg6j48SImJCluvPY03H9n5Ki6Y GXrZ0UD6GWfzGZAF3Rbbpj+WObUWxAXYII/dZi1+xgkFqulQjRa30udjD6A7rv0qxTkxob XshzR/GwakN2W2sGGhketN6YROhmq67lH5kIAiZju8NHf99pNpLQtZa9H1ZxIMoaE1Zu2/ hgnzWDQ86Frvncklzh+dkh9/EH4nPx5Lmk60cA2sZwoV/1LLiGvK94u9vPtMRFLltBk1TI NOe0IZ7rgSailn4yoGRzfgXmGYfB40MmbHMUHRqQHs1hmIO8UyFIXZX7ILOrpQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xz76401Nzz1KG8; Wed, 27 Nov 2024 18:20:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4ARIKRBp071283; Wed, 27 Nov 2024 18:20:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4ARIKREu071280; Wed, 27 Nov 2024 18:20:27 GMT (envelope-from git) Date: Wed, 27 Nov 2024 18:20:27 GMT Message-Id: <202411271820.4ARIKREu071280@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: 56ef9c872bc5 - main - nvi: use memmove to realign buffers 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 56ef9c872bc5b086d73fed6317159e40be32d40e Auto-Submitted: auto-generated The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=56ef9c872bc5b086d73fed6317159e40be32d40e commit 56ef9c872bc5b086d73fed6317159e40be32d40e Author: Brooks Davis AuthorDate: 2024-11-27 17:38:42 +0000 Commit: Brooks Davis CommitDate: 2024-11-27 18:20:04 +0000 nvi: use memmove to realign buffers Replace a rather convoluted realignment algorithm with memmove(). In addition to being hard to understand, the code would read beyond the end of the input buffer in certain conditions (found on CheriBSD). Sponsored by: DARPA Pull Request: https://github.com/lichray/nvi2/pull/122 --- contrib/nvi/common/log.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/contrib/nvi/common/log.c b/contrib/nvi/common/log.c index 96b246efad02..d9b142b16d01 100644 --- a/contrib/nvi/common/log.c +++ b/contrib/nvi/common/log.c @@ -706,30 +706,18 @@ apply_with(int (*db_func)(SCR *, recno_t, CHAR_T *, size_t), SCR *sp, recno_t lno, u_char *p, size_t len) { #ifdef USE_WIDECHAR - typedef unsigned long nword; - static size_t blen; - static nword *bp; - nword *lp = (nword *)((uintptr_t)p / sizeof(nword) * sizeof(nword)); - - if (lp != (nword *)p) { - int offl = ((uintptr_t)p - (uintptr_t)lp) << 3; - int offr = (sizeof(nword) << 3) - offl; - size_t i, cnt = (len + sizeof(nword) / 2) / sizeof(nword); + static u_char *bp; + if (!__builtin_is_aligned(p, sizeof(unsigned long))) { if (len > blen) { blen = p2roundup(MAX(len, 512)); - REALLOC(sp, bp, nword *, blen); + REALLOC(sp, bp, u_char *, blen); if (bp == NULL) return (1); } - for (i = 0; i < cnt; ++i) -#if BYTE_ORDER == BIG_ENDIAN - bp[i] = (lp[i] << offl) ^ (lp[i+1] >> offr); -#else - bp[i] = (lp[i] >> offl) ^ (lp[i+1] << offr); -#endif - p = (u_char *)bp; + memmove(bp, p, len); + p = bp; } #endif return db_func(sp, lno, (CHAR_T *)p, len / sizeof(CHAR_T));