Skip to content

Commit fd47dca

Browse files
authored
MONGOCRYPT-865 check returns of realloc (mongodb#1122)
1 parent 7bb6d3a commit fd47dca

4 files changed

Lines changed: 4 additions & 0 deletions

File tree

kms-message/src/kms_request_str.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ kms_request_str_reserve (kms_request_str_t *str, size_t size)
143143

144144
str->size = next_size;
145145
str->str = realloc (str->str, next_size);
146+
KMS_ASSERT(str->str);
146147
}
147148

148149
return str->str != NULL;

kms-message/test/test_kms_request.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ realloc_buffer (char **buffer, size_t *n, size_t len)
114114

115115
} else {
116116
*buffer = realloc (*buffer, len);
117+
KMS_ASSERT(*buffer);
117118
}
118119

119120
*n = len;

src/mc-mlib/str.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ static inline void mstrm_resize(mstr_mut *s, size_t new_len) {
247247
// enough to link it to the free() in mstr_free()
248248
assert(new_len < SIZE_MAX);
249249
s->raw.data = (char *)realloc((char *)s->raw.data, new_len + 1);
250+
assert(s->raw.data);
250251
#endif
251252
s->raw.len = new_len;
252253
assert(new_len >= old_len);

test/test-mc-text-search-str-encode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ static char *build_random_string_to_fold(uint32_t folded_len, uint32_t unfolded_
422422
uint32_t len = (uint32_t)(ptr - str);
423423
// ptr points to the final null character, include that in the final string.
424424
str = realloc(str, len + 1);
425+
ASSERT(str);
425426

426427
// Make sure we did everything right.
427428
ASSERT_CMPUINT32(unfolded_len, ==, get_utf8_codepoint_length(str, len));

0 commit comments

Comments
 (0)