From b5345ef4f08eee2b7e36853ca3efede44ab4a091 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 20 Aug 2017 21:19:29 +0100 Subject: [PATCH] crypto: use malloc instead of alloca --- src/crypto/crypto.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp index 1c7adff3b..5fb670f87 100644 --- a/src/crypto/crypto.cpp +++ b/src/crypto/crypto.cpp @@ -36,18 +36,13 @@ #include #include #include +#include #include "common/varint.h" #include "warnings.h" #include "crypto.h" #include "hash.h" -#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__) - #include -#else - #include -#endif - namespace crypto { using std::abort; @@ -411,7 +406,9 @@ POP_WARNINGS ge_p3 image_unp; ge_dsmp image_pre; ec_scalar sum, k, h; - rs_comm *const buf = reinterpret_cast(alloca(rs_comm_size(pubs_count))); + boost::shared_ptr buf(reinterpret_cast(malloc(rs_comm_size(pubs_count))), free); + if (!buf) + abort(); assert(sec_index < pubs_count); #if !defined(NDEBUG) { @@ -459,7 +456,7 @@ POP_WARNINGS sc_add(&sum, &sum, &sig[i].c); } } - hash_to_scalar(buf, rs_comm_size(pubs_count), h); + hash_to_scalar(buf.get(), rs_comm_size(pubs_count), h); sc_sub(&sig[sec_index].c, &h, &sum); sc_mulsub(&sig[sec_index].r, &sig[sec_index].c, &sec, &k); } @@ -471,7 +468,9 @@ POP_WARNINGS ge_p3 image_unp; ge_dsmp image_pre; ec_scalar sum, h; - rs_comm *const buf = reinterpret_cast(alloca(rs_comm_size(pubs_count))); + boost::shared_ptr buf(reinterpret_cast(malloc(rs_comm_size(pubs_count))), free); + if (!buf) + return false; #if !defined(NDEBUG) for (i = 0; i < pubs_count; i++) { assert(check_key(*pubs[i])); @@ -499,7 +498,7 @@ POP_WARNINGS ge_tobytes(&buf->ab[i].b, &tmp2); sc_add(&sum, &sum, &sig[i].c); } - hash_to_scalar(buf, rs_comm_size(pubs_count), h); + hash_to_scalar(buf.get(), rs_comm_size(pubs_count), h); sc_sub(&h, &h, &sum); return sc_isnonzero(&h) == 0; }