Skip to content

Commit 3369dd1

Browse files
Make sure we return the OOM error condition when closing containers
Usually, if you ignore the OOM error, the encoder API may start returning success, even though no buffer overrun happens. The way to check if an OOM happened is with cbor_encoder_get_extra_bytes_needed, which will return non-zero if a larger buffer is returned. That said, the API was mostly already returning the OOM error consistently, due to almost everything ending up calling append_to_buffer(). This case was an exception. Signed-off-by: Thiago Macieira <[email protected]>
1 parent 85c9f81 commit 3369dd1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/cborencoder.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *
534534
encoder->end = containerEncoder->end;
535535
if (containerEncoder->flags & CborIteratorFlag_UnknownLength)
536536
return append_byte_to_buffer(encoder, BreakByte);
537+
if (encoder->end)
538+
return CborErrorOutOfMemory; /* keep the state */
537539
return CborNoError;
538540
}
539541

0 commit comments

Comments
 (0)