Browse Source

Fixed copyAndReturn() possibly writing out-of-bound 0 in C API

Paul-Louis Ageneau 2 years ago
parent
commit
fe2112355b
1 changed files with 1 additions and 2 deletions
  1. 1 2
      src/capi.cpp

+ 1 - 2
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<const char *>(b.data());
 	std::copy(data, data + b.size(), buffer);
-	buffer[b.size()] = '\0';
 	return int(b.size());
 }