File 0707-erts-Fix-integer-overflow-in-loader.patch of Package erlang
From c14e0eea80911e36fe45839af96bb9593c63bbb6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org>
Date: Wed, 26 Jun 2019 09:28:28 +0200
Subject: [PATCH 2/2] erts: Fix integer overflow in loader
qsort expects the comparison function to return an int; returning
an `Sint` may yield nonsensical results.
---
erts/emulator/beam/beam_load.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/erts/emulator/beam/beam_load.c b/erts/emulator/beam/beam_load.c
index e61199a8fd..725b8006f7 100644
--- a/erts/emulator/beam/beam_load.c
+++ b/erts/emulator/beam/beam_load.c
@@ -4547,7 +4547,15 @@ typedef struct SortGenOpArg {
static int
genopargtermcompare(SortGenOpArg* a, SortGenOpArg* b)
{
- return CMP_TERM(a->term, b->term);
+ Sint res = CMP_TERM(a->term, b->term);
+
+ if (res < 0) {
+ return -1;
+ } else if (res > 0) {
+ return 1;
+ }
+
+ return 0;
}
static int
--
2.16.4