aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2019-01-05 13:40:05 -0800
committerDoug Hogan <[email protected]>2019-01-08 01:11:59 -0800
commit3db8a92c7ebb057574b65ac7ce041319da5d59a0 (patch)
tree7ef9dd6317153b410b053523a738e9812fa93266 /lib/crypto
parentbd895dd8f486dd740a267436b04e96a75a70f510 (diff)
downloadotp-3db8a92c7ebb057574b65ac7ce041319da5d59a0.tar.gz
otp-3db8a92c7ebb057574b65ac7ce041319da5d59a0.tar.bz2
otp-3db8a92c7ebb057574b65ac7ce041319da5d59a0.zip
Revamp CONSUME_REDS()
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/c_src/openssl_config.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/crypto/c_src/openssl_config.h b/lib/crypto/c_src/openssl_config.h
index e41d0c945e..7ea8c320ae 100644
--- a/lib/crypto/c_src/openssl_config.h
+++ b/lib/crypto/c_src/openssl_config.h
@@ -308,11 +308,16 @@
#define MAX_BYTES_TO_NIF 20000
#define CONSUME_REDS(NifEnv, Ibin) \
-do { \
- int _cost = ((Ibin).size * 100) / MAX_BYTES_TO_NIF;\
+do { \
+ size_t _cost = (Ibin).size; \
+ if (_cost > SIZE_MAX / 100) \
+ _cost = 100; \
+ else \
+ _cost = (_cost * 100) / MAX_BYTES_TO_NIF; \
+ \
if (_cost) { \
(void) enif_consume_timeslice((NifEnv), \
- (_cost > 100) ? 100 : _cost); \
+ (_cost > 100) ? 100 : (int)_cost); \
} \
} while (0)