From nobody Wed Feb 23 00:14:43 2022 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 5F4F419D4488; Wed, 23 Feb 2022 00:14:44 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4K3GkX0VWrz4Xgb; Wed, 23 Feb 2022 00:14:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645575284; 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=lRlHHb4VK/T9MsQxprId4U7QLk1WVM7zepP7dPBHyvk=; b=OfX+HmaWI5riuyifE5DVR0GZ8L7V0RXTx0rXvzEUaJ8ZNdv8CbD0wDLTLhgRXot26mCtBd X1PYeFhASNsrTiyMvfJe/Z1PCZ3RGOMBfMTkZ6/Ugc/4jNaO2QLSKZSn+D4AC3eB6VAffH DDH09yYRbyYsCYrZSoEnCw6mcAUgBchpGKhVXKVPHK6kzJ50gFb8P7inOMbWqlU8neIiWx t2/gz3jxPtZ5OAdyQg9Q4tirDCSlTio9wsTfKsYRKMtcP+y1npHDuXxviTtsyi7DBXuKTN Y6YhTUe9u+Z+bu1MQATTuf/JbKYEapBc3vCjcrzAihVHTwfXs/jiAcvCBAW2Pg== 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 8A4D9612E; Wed, 23 Feb 2022 00:14:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21N0EhTb079060; Wed, 23 Feb 2022 00:14:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21N0Ehrj079059; Wed, 23 Feb 2022 00:14:43 GMT (envelope-from git) Date: Wed, 23 Feb 2022 00:14:43 GMT Message-Id: <202202230014.21N0Ehrj079059@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michael Tuexen Subject: git: b6e6748b2b4a - stable/13 - sctp: avoid undefined behaviour and cleanup the code. 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b6e6748b2b4aca5b30226213201fdc61caee3cd3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645575284; 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=lRlHHb4VK/T9MsQxprId4U7QLk1WVM7zepP7dPBHyvk=; b=qAkhRJqVcT5mP9j2/b8XqtpAQy3MiwY3D73S8fNfR+LKzT8R91hKjULNhf2NIOw1zNshKd Uk/ZEbZH+XB9Uee/NvRiaj+eE7MiUcZCLnb8a7V5oU6LqNPwFSNN9eXVo++VCelKhYG/la 86c7nk3AMsYZRsy/uxIXWqKoGo3ciAbjzIF3F+50ael6YTGjzeFzOV2MFegddFeoI8DsH0 i/99e/VjD1C0uFYPwSK1b/wpvTfmu2GGf8IcFUjf34zNDf95jmiUWtQg14hTyxuWZhAakn 7xrjb5VeIr2086rczUTfSRMXn74uY8LcJb0vl94fCxQBPoPkJCeR3uaCd2u9ug== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645575284; a=rsa-sha256; cv=none; b=ehgjjpqx6j0Uy/gWCoiJH0NG/eeHGTXK8piAr7YUDsMYyRxVZfKQgPAeiGxyR+NcSf9N6c 5laU4nm7d2JavYdV2TBhfT+taKuG6CvmuuntqPZWFwsf9NWt+k/UplADQl5FiZafhxdH7K XehSnJ/hI5gN5EXoj1T/dynNCTQCWsa0BhZy+rh20fHvP04gEhdEjWzDg8nMXBpAw2IZIT 21NXYXkwDTmKPAPHMRObCrMLd0CthqlF9rlw8XNjIm1FPtX3NGJQLhzamqvP/sK1n2TNpj P30FDC+H3dd/mFVkH7aUQhfTjdlM7batjxSKcOHPdzkxnR8kEtrsgsXc3DPzJg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=b6e6748b2b4aca5b30226213201fdc61caee3cd3 commit b6e6748b2b4aca5b30226213201fdc61caee3cd3 Author: Michael Tuexen AuthorDate: 2022-02-17 18:23:59 +0000 Commit: Michael Tuexen CommitDate: 2022-02-23 00:13:10 +0000 sctp: avoid undefined behaviour and cleanup the code. (cherry picked from commit 76e03cc940fed57d580b1d5c0605e8af2e14f05b) --- sys/netinet/sctp_crc32.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/sys/netinet/sctp_crc32.c b/sys/netinet/sctp_crc32.c index 97b881bb5062..9e17637d74d6 100644 --- a/sys/netinet/sctp_crc32.c +++ b/sys/netinet/sctp_crc32.c @@ -52,32 +52,25 @@ __FBSDID("$FreeBSD$"); static uint32_t sctp_finalize_crc32c(uint32_t crc32c) { - uint32_t result; #if BYTE_ORDER == BIG_ENDIAN - uint8_t byte0, byte1, byte2, byte3; + uint32_t byte0, byte1, byte2, byte3; #endif - /* Complement the result */ - result = ~crc32c; #if BYTE_ORDER == BIG_ENDIAN /* - * For BIG-ENDIAN platforms the result is in little-endian form. So - * we must swap the bytes to return the result in network byte - * order. + * For BIG-ENDIAN platforms, the result is in LITTLE-ENDIAN byte + * order. For LITTLE-ENDIAN platforms, the result is in in + * BIG-ENDIAN byte order. So for BIG-ENDIAN platforms the bytes must + * be swapped to return the result always in network byte order (aka + * BIG-ENDIAN). */ - byte0 = result & 0x000000ff; - byte1 = (result >> 8) & 0x000000ff; - byte2 = (result >> 16) & 0x000000ff; - byte3 = (result >> 24) & 0x000000ff; + byte0 = crc32c & 0x000000ff; + byte1 = (crc32c >> 8) & 0x000000ff; + byte2 = (crc32c >> 16) & 0x000000ff; + byte3 = (crc32c >> 24) & 0x000000ff; crc32c = ((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3); -#else - /* - * For LITTLE ENDIAN platforms the result is in already in network - * byte order. - */ - crc32c = result; #endif - return (crc32c); + return (~crc32c); } static int