From d8d6cae525e99eca2259fc8803d80e5dc077718b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 10 Dec 2019 00:39:20 +0000 Subject: [PATCH] libsolc: truncate input C strings to trailing zero --- libsolc/libsolc.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libsolc/libsolc.cpp b/libsolc/libsolc.cpp index 4c0f3b30f..618fb741e 100644 --- a/libsolc/libsolc.cpp +++ b/libsolc/libsolc.cpp @@ -62,6 +62,14 @@ string takeOverAllocation(char const* _data) abort(); } +/// Resizes a std::string to the proper length based on the occurrence of a zero terminator. +void truncateCString(string& _data) +{ + size_t pos = _data.find('\0'); + if (pos != string::npos) + _data.resize(pos); +} + ReadCallback::Callback wrapReadCallback(CStyleReadFileCallback _readCallback, void* _readContext) { ReadCallback::Callback readCallback; @@ -89,6 +97,7 @@ ReadCallback::Callback wrapReadCallback(CStyleReadFileCallback _readCallback, vo result.success = false; result.responseOrErrorMessage = takeOverAllocation(error_c); } + truncateCString(result.responseOrErrorMessage); return result; }; }