Skip to content

Commit 159588b

Browse files
committed
Merge pull request #744 from pguyot/w32/debug-crypto-test
Fix issue related to hash of non iolists These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents b203ce1 + b1fc807 commit 159588b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/platforms/esp32/components/avm_sys/platform_nifs.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,13 @@ static term nif_esp_sleep_enable_ext1_wakeup(Context *ctx, int argc, term argv[]
454454
{ \
455455
mbedtls_##ALGORITHM##_context *md_ctx = (mbedtls_##ALGORITHM##_context *) accum; \
456456
if (term_is_integer(t)) { \
457-
uint8_t val = term_to_uint8(t); \
457+
avm_int64_t tmp = term_maybe_unbox_int64(t); \
458+
if (tmp < 0 || tmp > 255) { \
459+
return InteropBadArg; \
460+
} \
461+
uint8_t val = (uint8_t) tmp; \
458462
mbedtls_##ALGORITHM##_update##SUFFIX(md_ctx, &val, 1); \
459-
} else if (term_is_binary(t)) { \
463+
} else /* term_is_binary(t) */ { \
460464
mbedtls_##ALGORITHM##_update(md_ctx, (uint8_t *) term_binary_data(t), term_binary_size(t)); \
461465
} \
462466
return InteropOk; \
@@ -492,7 +496,7 @@ static term nif_esp_sleep_enable_ext1_wakeup(Context *ctx, int argc, term argv[]
492496
} \
493497
uint8_t val = (avm_int64_t) tmp; \
494498
mbedtls_##ALGORITHM##_update##SUFFIX(md_ctx, &val, 1); \
495-
} else if (term_is_binary(t)) { \
499+
} else /* term_is_binary(t) */ { \
496500
mbedtls_##ALGORITHM##_update(md_ctx, (uint8_t *) term_binary_data(t), term_binary_size(t)); \
497501
} \
498502
return InteropOk; \

0 commit comments

Comments
 (0)