From nobody Fri Jun 23 04:35:44 2023 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 4QnPYr5SXVz4gP7G; Fri, 23 Jun 2023 04:35: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 4QnPYr4Ymnz4PZQ; Fri, 23 Jun 2023 04:35:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687494944; 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=yrsfLeKMhD+iSnBQYIAnkp3urAEFPcIFA4alhGzTK68=; b=hX/7dTCNj7i4Q4heCs874Npr0m0GOHDUY7v/KicIxgnpNptmoEmQYu28HZ99FHMY7FF0ms uO2h7w8EwBNAGZtJ2sQ5xhWLvoNlCEvIBLPAHAG7WYnNFTuNiVy9Q5QBGYN73oRCJowBut 7Etmr4uVS3Yo7+zpYhdmpbZyYBSwLLn3pNXhoRLJJzck5l4B+Y5ve9thstAN7Ni7JM01hi 08c6P5UIHmHZHdgIi7BCd80rtxG7C6b8h08tqMYm5aIqckusAWaIWNnv9F6MorCgFDof5f oESdpfpUrNJnHxKrPfqo9dzD4nglITdS3AYagPOuVv2jRRgXjnViVETQaWRu1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687494944; 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=yrsfLeKMhD+iSnBQYIAnkp3urAEFPcIFA4alhGzTK68=; b=DG0RGkAg6m4Ja+OwtJTx25AeuZ3pG1Yt2rPNrDp+/Ps/LLXr+RDMlf3t6+Qc2+3cO4X0mp Mza2rfLBD6LAx/euIVjEx3yY6GRQoQot+QvQbc6uEsmBQ+T5dLt1G3Ljc6Ki2Bd+cFBFIv uCfRSVJCIHRjni0Q4v+Q1Py1Z3a2v4CpqX/MnZp+Vsa37yHsK1Mzw/l0eER3cKjpDJMXmR 4Yg1czfji0PAqLHWoGeDRSV8vhH61cRkO8oVc7NBPF90z6q//EVqD6geA6p2ku8WRb4QlR KqmzFWotCYH57b5c63TK0BlCwbmoCHuOkwhhuo9Hox1kmopmkWN87uFHyP58xg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687494944; a=rsa-sha256; cv=none; b=rbA7c+UzE5BIWvE3kiZdgTvP00S1VntMJrMM9QAxavokVZcuuZqUwNpl3ylO1n0kNuOr+g y6TRNbXrlgFNZfEyGWl/4YLJVlwSgx9vLUUt2HPRKgBGMRDKQ45AYfmIsO8wzCONnfh5RA LHzAd47ncB0qxYchCE4paO4QwVxW+dRM7Vu70NftWCKcDrHuU/EaudDpIKM/DNBTQHJG9P J0a8pX0STAmy3Lgou3OGdbGg929HrqihO5tS5LuCpiOjrrow8XTj1cw12lleWl85fpeV7T RPVdwWExrwAljkfNogSdvjxt/lNgzoYQhkTZqPrgt7Epin3m2LIe4pO8bLCv9Q== 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 4QnPYr3dwlzrYw; Fri, 23 Jun 2023 04:35:44 +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 35N4ZiwX099358; Fri, 23 Jun 2023 04:35:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35N4Zidb099357; Fri, 23 Jun 2023 04:35:44 GMT (envelope-from git) Date: Fri, 23 Jun 2023 04:35:44 GMT Message-Id: <202306230435.35N4Zidb099357@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Cy Schubert Subject: git: e66b677c9745 - stable/12 - kern_ntptime: Fix undefined behavior of the shift operator 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: cy X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: e66b677c974540ccf55d7a73a3ce220721f4d0ea Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=e66b677c974540ccf55d7a73a3ce220721f4d0ea commit e66b677c974540ccf55d7a73a3ce220721f4d0ea Author: Dmitriy Alexandrov AuthorDate: 2023-06-08 09:08:46 +0000 Commit: Cy Schubert CommitDate: 2023-06-23 04:35:04 +0000 kern_ntptime: Fix undefined behavior of the shift operator L_LINT macro is used with negative numbers [i.e. L_LINT(time_freq, -MAXFREQ)], it could cause undefined behavior. It should be similar to the L_RSHIFT(v, n) macro. MFC after: 2 weeks Reviewed by: cy Pull Request: https://github.com/freebsd/freebsd-src/pull/769 Signed-off-by: Dmitriy Alexandrov (cherry picked from commit af9ce4e9bb7d717279e02d46455e85ef6fb828f7) --- sys/kern/kern_ntptime.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_ntptime.c b/sys/kern/kern_ntptime.c index bc35cdee0d71..2817d2f20d5a 100644 --- a/sys/kern/kern_ntptime.c +++ b/sys/kern/kern_ntptime.c @@ -73,7 +73,13 @@ typedef int64_t l_fp; #define L_MPY(v, a) ((v) *= (a)) #define L_CLR(v) ((v) = 0) #define L_ISNEG(v) ((v) < 0) -#define L_LINT(v, a) ((v) = (int64_t)(a) << 32) +#define L_LINT(v, a) \ + do { \ + if ((a) < 0) \ + ((v) = -((int64_t)(-(a)) << 32)); \ + else \ + ((v) = (int64_t)(a) << 32); \ + } while (0) #define L_GINT(v) ((v) < 0 ? -(-(v) >> 32) : (v) >> 32) /*