]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: Use int64_t for intermediate values in int32_MINMAX to
authortobhe@openbsd.org <tobhe@openbsd.org>
Wed, 30 Dec 2020 14:13:28 +0000 (14:13 +0000)
committerDamien Miller <djm@mindrot.org>
Thu, 31 Dec 2020 01:42:16 +0000 (12:42 +1100)
prevent signed 32-bit integer overflow.

Found by and ok djm@
ok markus@

OpenBSD-Commit-ID: 4f0704768e34cf45fdd792bac4011c6971881bb3

int32_minmax.inc [new file with mode: 0644]

diff --git a/int32_minmax.inc b/int32_minmax.inc
new file mode 100644 (file)
index 0000000..2f6ff51
--- /dev/null
@@ -0,0 +1,20 @@
+/*  $OpenBSD: int32_minmax.inc,v 1.1 2020/12/30 14:13:28 tobhe Exp $ */
+
+/*
+ * Public Domain, Authors:
+ * - Daniel J. Bernstein
+ * - Chitchanok Chuengsatiansup
+ * - Tanja Lange
+ * - Christine van Vredendaal
+ */
+
+#define int32_MINMAX(a,b) \
+do { \
+  int64_t ab = (int64_t)b ^ (int64_t)a; \
+  int64_t c = (int64_t)b - (int64_t)a; \
+  c ^= ab & (c ^ b); \
+  c >>= 31; \
+  c &= ab; \
+  a ^= c; \
+  b ^= c; \
+} while(0)