Skip to content

Commit 77a452e

Browse files
committed
CDRIVER-2933 fix oob access in oid test
1 parent d62b610 commit 77a452e

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/libbson/tests/test-oid.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <strings.h>
2727
#endif
2828

29+
#include <limits.h>
30+
2931
#include "TestSuite.h"
3032

3133
#define N_THREADS 4
@@ -524,24 +526,30 @@ _mock_hostname (char *out)
524526
}
525527

526528

529+
#ifndef HOST_NAME_MAX
530+
#define HOST_NAME_MAX 256
531+
#endif
532+
533+
527534
static void
528535
test_bson_hostnames (void)
529536
{
530537
bson_context_t *ctx;
531538
bson_oid_t oid;
532-
char *hostname_tests[] = {
533-
"",
534-
"h",
535-
"host"
536-
"host1",
537-
"host12",
538-
"host123",
539-
"test_the_maximum_length_string.............................."
540-
"............................................................"
541-
"............................................................"
542-
"............................................................"
543-
"............."};
539+
char *hostname_tests[] = {"",
540+
"h",
541+
"host"
542+
"host1",
543+
"host12",
544+
"host123",
545+
"placeholder"};
544546
int i;
547+
char max_len_host[HOST_NAME_MAX] = {0};
548+
549+
for (i = 0; i < HOST_NAME_MAX - 1; i++) {
550+
max_len_host[i] = "a";
551+
}
552+
hostname_tests[sizeof(hostname_tests) - 1] = max_len_host;
545553

546554
for (i = 0; i < sizeof (hostname_tests) / sizeof (char *); i++) {
547555
mock_hostname = hostname_tests[i];

0 commit comments

Comments
 (0)