diff options
author | Kjell Winblad <[email protected]> | 2019-02-14 15:32:06 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-02-14 15:32:06 +0100 |
commit | acf97f8bcb4846bdc5935770b22ce1cb84a90a15 (patch) | |
tree | 579a2f1e8754130aaa59c636ce2e4335a73d0746 /erts/emulator/beam | |
parent | f45efdd2663b8050edb4351a8d1d57d437fb6e51 (diff) | |
parent | 1df3d85824601e3c07d12ca9811866c2ef334e76 (diff) | |
download | otp-acf97f8bcb4846bdc5935770b22ce1cb84a90a15.tar.gz otp-acf97f8bcb4846bdc5935770b22ce1cb84a90a15.tar.bz2 otp-acf97f8bcb4846bdc5935770b22ce1cb84a90a15.zip |
Merge pull request #2118 from kjellwinblad/fix_valgrind_problem_bignum OTP-15583
Fix bug in binary:encode_unsigned causing a read of uninitialized memory
Diffstat (limited to 'erts/emulator/beam')
-rw-r--r-- | erts/emulator/beam/erl_bif_binary.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/erts/emulator/beam/erl_bif_binary.c b/erts/emulator/beam/erl_bif_binary.c index a2610bf2e1..ae1bf6e652 100644 --- a/erts/emulator/beam/erl_bif_binary.c +++ b/erts/emulator/beam/erl_bif_binary.c @@ -2762,7 +2762,7 @@ static BIF_RETTYPE do_encode_unsigned(Process *p, Eterm uns, Eterm endianess) dsize_t num_parts = BIG_SIZE(bigp); Eterm res; byte *b; - ErtsDigit d; + ErtsDigit d = 0; if(BIG_SIGN(bigp)) { goto badarg; @@ -2778,26 +2778,22 @@ static BIF_RETTYPE do_encode_unsigned(Process *p, Eterm uns, Eterm endianess) if (endianess == am_big) { Sint i,j; j = 0; - d = BIG_DIGIT(bigp,0); for (i=n-1;i>=0;--i) { - b[i] = d & 0xFF; - if (!((++j) % sizeof(ErtsDigit))) { + if (!((j++) % sizeof(ErtsDigit))) { d = BIG_DIGIT(bigp,j / sizeof(ErtsDigit)); - } else { - d >>= 8; } + b[i] = d & 0xFF; + d >>= 8; } } else { Sint i,j; j = 0; - d = BIG_DIGIT(bigp,0); for (i=0;i<n;++i) { - b[i] = d & 0xFF; - if (!((++j) % sizeof(ErtsDigit))) { + if (!((j++) % sizeof(ErtsDigit))) { d = BIG_DIGIT(bigp,j / sizeof(ErtsDigit)); - } else { - d >>= 8; } + b[i] = d & 0xFF; + d >>= 8; } } |