Skip to content
Open
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
5 changes: 3 additions & 2 deletions src/cbortojson.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ static CborError escape_text_string(char **str, size_t *alloc, size_t *offsetp,
return CborErrorDataTooLarge;
}
if (!alloc || needed > *alloc) {
buf = cbor_realloc(buf, needed);
if (!buf)
char *tmp = cbor_realloc(buf, needed);
if (!tmp)
return CborErrorOutOfMemory;
buf = tmp;
Comment on lines +332 to +335
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if there is a problem with freeing, this patch isn't solving it. buf is a local variable in this function, so adding yet another temporary is not going to help. This code will compile to exactly the same assembly before and after the change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thiagomacieira, how do you propose a change so that its more secure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm saying it's already secure.

if (alloc)
*alloc = needed;
}
Expand Down