From nobody Fri Apr 24 15:29:06 2026 X-Original-To: dev-commits-src-all@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 4g2H1b4hrqz6bSGJ for ; Fri, 24 Apr 2026 15:29:07 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g2H1b00Nhz3CyC for ; Fri, 24 Apr 2026 15:29:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777044547; 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=RswJuOE1ze1xdH7oh5VJuxO1PiZfHGudxzuBhOhJo4U=; b=i9IPqA7ZkTJCIvqjBSIo7X0EGqITvPqHU+FexOvevz7xNa0zdZG5V28hAF1Ht/Oty68Yjh rZI06mvbPQw8dOzFdidTzBBQhn7VDQ/jshz3w72H7CGz6fAZ/uLiH8z2OrYFWLIXHrzTuo wBGr0siET069b4ZCiB6U9PR1yS6bas1hSssxjlt64ySeIsaQiJFMJxnPI3/UlDmI2DxNaf nicm91Jb7ETP0C03Quy/9E5OXAObLGHvHFWh1zA0ttNjAEWalWzw3axXNW8s8zW08c3g9h 1OAHW4ij3JyvAx3Wbc39yt5DHu2N8yokOPuQ50IM43sleQ35OLoVx79a3HXzvA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777044547; a=rsa-sha256; cv=none; b=ZNbkOP7pHzGPOb3R6zktMsOgOCOPyuaWbkx9CqOMgH2Imp0/QC9OcW6aRwSKLOGyksIwKB bd9tFlKl+1yHFXUq6UDpykJYXXskA5zDAsFwdqp9hO0HnjGoq18OXl/k+7V7XeYlOPdZyW AWAg0ApH8QjnP3BHNW2h/gdIhtOXpc0yL3RD5Tfgp8KBakpSuxMWC/jw4vArhpgjyoPBmy TcttVwp6W35uyAYaIaS4mq6I0Kdk28piYGiUl8kgZ6mIhJzzPVXPTbvv7LPuiHYNgk11sD wJAHrtEgeVf6EpFRjTKmi9RbinYuLNxN7n+VBMkMYd8KcmUULzyE4YMGZ1UC6Q== 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=1777044547; 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=RswJuOE1ze1xdH7oh5VJuxO1PiZfHGudxzuBhOhJo4U=; b=gsgLxn6zSh7l6zVUtIHXbuN71PuE39ozG2v9AdXwv857fn6CmChEFlVO4DbsSPjIKrL7sR ndV65ZxyqKqhuRj6ngPpOKgOthkB+/5ztD4jpEPCyns76orq2V9lDk/hSaAKh6SwWDnxyg vPdugC02+7frfwjJ5ImlxIo5OWCbG3mxUsl1fvidx95thquXWaCFKKcgj0NRc7NV0amkb1 YSx+8tJ4iGrrhkb78MOlbdGjaPKiJ+OOR5Hn0jl4DkPunw7iPYguEcNoWkmLu2ruZwD9QQ 6ScCLSZrcarEo7ZiiE8OVnIqWWZ9MH2yTB9yKL6am3KYx3DNIANDU/M1+lED/A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g2H1Z6Nqqz17nW for ; Fri, 24 Apr 2026 15:29:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 36980 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 24 Apr 2026 15:29:06 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: deebb011a443 - stable/15 - swab: Correctly treat the data as misaligned List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: deebb011a443f45a0ab13c7a48cbaf5c846aef38 Auto-Submitted: auto-generated Date: Fri, 24 Apr 2026 15:29:06 +0000 Message-Id: <69eb8c42.36980.5a57406b@gitrepo.freebsd.org> The branch stable/15 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=deebb011a443f45a0ab13c7a48cbaf5c846aef38 commit deebb011a443f45a0ab13c7a48cbaf5c846aef38 Author: John Baldwin AuthorDate: 2026-01-14 17:10:33 +0000 Commit: John Baldwin CommitDate: 2026-04-24 15:26:38 +0000 swab: Correctly treat the data as misaligned The __aligned attribute in the previous version applied to the location of the pointers, not the data the pointers pointed to. While this could be fixed by applying the attribute to a local typedef of uint16_t, just using memcpy() for the unaligned access is simpler and ISO C. This fixes the build on CHERI architectures which do not support misaligned pointers and were thus failing with: lib/libc/string/swab.c:12:18: error: alignment (1) of 'const uint16_t *' (aka 'const unsigned short *') is less than the required capability alignment (16) [-Werror,-Wcheri-capability-misuse] 12 | const uint16_t *f __aligned(1) = from; | Co-authored by: Jessica Clarke Fixes: 02ebbc781f08 ("swab: Fix implementation to support overlapping copies") Sponsored by: AFRL, DARPA Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54399 (cherry picked from commit 2a5c5b8f7cddf14537707895fceb454cabc1b3bd) --- lib/libc/string/swab.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/libc/string/swab.c b/lib/libc/string/swab.c index ed4436a49810..4f4fb26379c6 100644 --- a/lib/libc/string/swab.c +++ b/lib/libc/string/swab.c @@ -3,14 +3,16 @@ * Copyright (c) 2024 rilysh */ +#include #include #include void swab(const void * __restrict from, void * __restrict to, ssize_t len) { - const uint16_t *f __aligned(1) = from; - uint16_t *t __aligned(1) = to; + const char *f = from; + char *t = to; + uint16_t tmp; /* * POSIX says overlapping copy behavior is undefined, however many @@ -19,7 +21,12 @@ swab(const void * __restrict from, void * __restrict to, ssize_t len) * and swapping them before writing them back accomplishes this. */ while (len > 1) { - *t++ = bswap16(*f++); + memcpy(&tmp, f, 2); + tmp = bswap16(tmp); + memcpy(t, &tmp, 2); + + f += 2; + t += 2; len -= 2; } }