Browse Source

Merge pull request #798 from paullouisageneau/fix-capi-copy-out-of-bounds

Fix possible out-of-bound zero character in C API
Paul-Louis Ageneau 2 years ago
parent
commit
bbf386463c
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)
 	if (!buffer)
 		return int(s.size() + 1);
 		return int(s.size() + 1);
 
 
-	if (size < int(s.size()))
+	if (size < int(s.size() + 1))
 		return RTC_ERR_TOO_SMALL;
 		return RTC_ERR_TOO_SMALL;
 
 
 	std::copy(s.begin(), s.end(), buffer);
 	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());
 	auto data = reinterpret_cast<const char *>(b.data());
 	std::copy(data, data + b.size(), buffer);
 	std::copy(data, data + b.size(), buffer);
-	buffer[b.size()] = '\0';
 	return int(b.size());
 	return int(b.size());
 }
 }