Skip to content

Commit

Permalink
Merge pull request #798 from paullouisageneau/fix-capi-copy-out-of-bo…
Browse files Browse the repository at this point in the history
…unds

Fix possible out-of-bound zero character in C API
  • Loading branch information
paullouisageneau authored Feb 2, 2023
2 parents 791d520 + fe21123 commit bbf3864
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}

Expand Down

0 comments on commit bbf3864

Please sign in to comment.