aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/beam_load.c
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2019-06-26 09:28:28 +0200
committerJohn Högberg <[email protected]>2019-07-01 11:23:28 +0200
commitc14e0eea80911e36fe45839af96bb9593c63bbb6 (patch)
treebe7237de08fb7edbf9fdc5469222f51cc264330b /erts/emulator/beam/beam_load.c
parenta055766e0ca9d2b4a5007f00b007b087e06bc7a5 (diff)
downloadotp-c14e0eea80911e36fe45839af96bb9593c63bbb6.tar.gz
otp-c14e0eea80911e36fe45839af96bb9593c63bbb6.tar.bz2
otp-c14e0eea80911e36fe45839af96bb9593c63bbb6.zip
erts: Fix integer overflow in loader
qsort expects the comparison function to return an int; returning an `Sint` may yield nonsensical results.
Diffstat (limited to 'erts/emulator/beam/beam_load.c')
-rw-r--r--erts/emulator/beam/beam_load.c10
1 files changed, 9 insertions, 1 deletions
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