From fe2112355b0e425b0c4f01e5f4b25307de66badd Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Thu, 2 Feb 2023 01:24:18 +0100 Subject: [PATCH] Fixed copyAndReturn() possibly writing out-of-bound 0 in C API --- src/capi.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/capi.cpp b/src/capi.cpp index e1dbe6751..e055f084a 100644 --- a/src/capi.cpp +++ b/src/capi.cpp @@ -188,7 +188,7 @@ int copyAndReturn(string s, char *buffer, int size) { if (!buffer) return int(s.size() + 1); - if (size < int(s.size())) + if (size < int(s.size() + 1)) return RTC_ERR_TOO_SMALL; std::copy(s.begin(), s.end(), buffer); @@ -205,7 +205,6 @@ int copyAndReturn(binary b, char *buffer, int size) { auto data = reinterpret_cast(b.data()); std::copy(data, data + b.size(), buffer); - buffer[b.size()] = '\0'; return int(b.size()); }