Skip to content

Fix buffer overflow in _cbor_value_copy_string #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cborparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,7 @@ CborError _cbor_value_copy_string(const CborValue *value, void *buffer,
size_t *buflen, CborValue *next)
{
bool copied_all;
size_t maxlen = *buflen;
CborError err = iterate_string_chunks(value, (char*)buffer, buflen, &copied_all, next,
buffer ? (IterateFunction) value->parser->d->cpy : iterate_noop);
if (err) {
Expand All @@ -1303,7 +1304,7 @@ CborError _cbor_value_copy_string(const CborValue *value, void *buffer,
return CborErrorOutOfMemory;
}

if (buffer) {
if (buffer && *buflen < maxlen) {
*((uint8_t *)buffer + *buflen) = '\0';
}

Expand Down