From nobody Thu Feb 17 18:25:04 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 7C9E019E5DD4; Thu, 17 Feb 2022 18:25:04 +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 4K03CN2zXCz4m9m; Thu, 17 Feb 2022 18:25:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645122304; 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=PRAXEqE3yEsyQlunwYDkVAS5MLVwR7vw8aUnOfhpsmk=; b=A1fpGA0aEmIzC9Qtp93nisYUR6ghSJvlyQI9ZNWCgb5XDTBVgzrypESnBYMcZBft20JzFG dmibC8tRQce6zzWEhfUD+G3e3IRwrfKFeVIbNPWjimSkTB0zbc0yK1In4O6tWjSK8/1rv3 7QdM6ts0RPIdaYSVVOGMKIMhjwc16Kmsr7aDg7752qcVaQsG2Mt55bkBYE6Bud9yxpvhTA k7NNgXLfy4HndTNzzsCcJc4GwuMxcrfyecR9iYDHoH+WO3uj6ej3XOkG27DiTVzvPljh4i tQkVcYx90dBCM+DAapOQvnfdRy3WBLnpRdBHWAshVXJ6BrSfnqzIDmCTDsmZAg== 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 3CF516D16; Thu, 17 Feb 2022 18:25:04 +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 21HIP4MS023991; Thu, 17 Feb 2022 18:25:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21HIP4Es023990; Thu, 17 Feb 2022 18:25:04 GMT (envelope-from git) Date: Thu, 17 Feb 2022 18:25:04 GMT Message-Id: <202202171825.21HIP4Es023990@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michael Tuexen Subject: git: 76e03cc940fe - main - 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/main X-Git-Reftype: branch X-Git-Commit: 76e03cc940fed57d580b1d5c0605e8af2e14f05b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645122304; 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=PRAXEqE3yEsyQlunwYDkVAS5MLVwR7vw8aUnOfhpsmk=; b=tnJ80V/u4AphuhGCLa2avt0Fz5QunlysKySCJKfYHRG+Gv4MP5zYT0x4RAQTT7krvsiMYq +qlFuVyzaxcfNn2j3gmHBjcXQkLm2XrrgxT+wF7HDR+k9qzrXSxaOnknkSbxrG8xeop9mJ jYtDcN/bvARXxOylalSP70KvCkwQIasXebsGzSNHboMITx24XROycG9b6OIN6W9kwTtQ4k 39wP3sG2MHbm9m4DZR2hunE1vUuGlhTL26G4PfsZpSJJ0sDz5kh0qN59ETnNrWL0gcC4eU vy6f9Tvh3udeHoHxrSppENDhu90AT2xpOlLDFbqTKpCoCUuX2zm/DyHdT5VWSg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645122304; a=rsa-sha256; cv=none; b=hNfFkh/9UDsDyv8ZSPX74iawP72xY+44DcXo2S6medk695BLnlKWddumG3I3c7soeeTFQS XC5V+F64eCc9Cib+yANWbYSOy7bc4Lr4HS5NCbELq54/nzveyPRgH7scsmR/qRqwSQvnZ1 QFSmIQmMUeaP7DHZpswhKjlwQmOn3AJYj+lvcuertfGW+4i1vh4Akj7UmgwuobS9fd8B05 BzG9f9cHK5YnkdTQNmY9wAxGt2+F+lla/QVacaa79WUnmC+U0QZebTsWDMTzbMflQFPvPs +G9YGgPssqtL6nEXEbV42C4jH5YyLRpDPIG9ZupQRzmv7Gq0gT148IccKFyisA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=76e03cc940fed57d580b1d5c0605e8af2e14f05b commit 76e03cc940fed57d580b1d5c0605e8af2e14f05b Author: Michael Tuexen AuthorDate: 2022-02-17 18:23:59 +0000 Commit: Michael Tuexen CommitDate: 2022-02-17 18:23:59 +0000 sctp: avoid undefined behaviour and cleanup the code. MFC after: 3 days --- 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