Skip to content

Commit e575581

Browse files
authored
Merge branch 'NLnetLabs:main' into main
2 parents 08022be + 60ce4d7 commit e575581

File tree

9 files changed

+21
-13
lines changed

9 files changed

+21
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Fixed
1313

14+
- Fix tests to initialize padding (#252).
15+
1416
## [0.2.2] - 2025-04-24
1517

1618
### Added

tests/base32.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void base32_syntax(void **state)
7676
zone_options_t options;
7777
int32_t result;
7878

79+
memset(rr, 0, sizeof(rr));
7980
(void)snprintf(rr, sizeof(rr), rrfmt, tests[i].base32);
8081

8182
fprintf(stderr, "INPUT: '%s'\n", rr);

tests/bounds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void block_boundary(void **state)
160160

161161
for (int i=0, n=sizeof(tests)/sizeof(tests[0]); i < n; i++) {
162162
// allocate memory instead of using a static buffer for asan
163-
char *input = malloc(tests[i].length + 64);
163+
char *input = calloc(tests[i].length + ZONE_BLOCK_SIZE, 1);
164164
assert_non_null(input);
165165
memcpy(input, tests[i].input, tests[i].length);
166166
memset(&parser, 0, sizeof(parser));

tests/include.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int setup(void **state)
112112

113113
#define FMT "$INCLUDE %s\n"
114114
len = (strlen(FMT) - 2) + strlen(input->include.path);
115-
if (!(input->includer.content = malloc(len+1 + ZONE_BLOCK_SIZE)))
115+
if (!(input->includer.content = calloc(len+1 + ZONE_BLOCK_SIZE, 1)))
116116
goto err;
117117
(void)snprintf(input->includer.content, len+1, FMT, input->include.path);
118118
if (fputs(input->includer.content, input->includer.handle) == EOF)
@@ -122,7 +122,7 @@ int setup(void **state)
122122
#undef FMT
123123
#define FMT "host.example.com. 3600 IN TXT foobar\n"
124124
len = strlen(FMT);
125-
if (!(input->include.content = malloc(len+1 + ZONE_BLOCK_SIZE)))
125+
if (!(input->include.content = calloc(len+1 + ZONE_BLOCK_SIZE, 1)))
126126
goto err;
127127
(void)snprintf(input->include.content, len+1, FMT);
128128
if (fputs(input->include.content, input->include.handle) == EOF)
@@ -173,7 +173,7 @@ static int32_t parse(
173173

174174
int32_t code;
175175
size_t length = strlen(text);
176-
char *string = malloc(length + 1 + ZONE_BLOCK_SIZE);
176+
char *string = calloc(length + 1 + ZONE_BLOCK_SIZE, 1);
177177
assert_non_null(string);
178178
memcpy(string, text, length);
179179
string[length] = '\0';
@@ -486,7 +486,7 @@ void been_there_done_that(void **state)
486486
char dummy[16];
487487
int length = snprintf(dummy, sizeof(dummy), "$INCLUDE \"%s\"\n", path);
488488
assert_true(length > 0 && length < INT_MAX - ZONE_BLOCK_SIZE);
489-
char *include = malloc((size_t)length + 1 + ZONE_BLOCK_SIZE);
489+
char *include = calloc((size_t)length + 1 + ZONE_BLOCK_SIZE, 1);
490490
assert_non_null(include);
491491
(void)snprintf(include, (size_t)length + 1, "$INCLUDE \"%s\"\n", path);
492492
int result = fputs(include, handle);
@@ -693,7 +693,7 @@ diagnostic_pop()
693693
int len = snprintf(buf, sizeof(buf), fmt, paths[0]);
694694
assert_true(len > 0);
695695

696-
char *str = malloc((size_t)len + ZONE_BLOCK_SIZE + 1);
696+
char *str = calloc((size_t)len + ZONE_BLOCK_SIZE + 1, 1);
697697
assert_non_null(str);
698698
(void)snprintf(str, (size_t)len+1, fmt, paths[0]);
699699

tests/ip4.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void ipv4_syntax(void **state)
8989
zone_options_t options;
9090
int32_t result;
9191

92+
memset(rr, 0, sizeof(rr));
9293
(void)snprintf(rr, sizeof(rr), "foo. A %s", tests[i].address);
9394

9495
fprintf(stderr, "INPUT: %s\n", rr);

tests/semantics.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ void ds_digest_lengths(void **state)
117117
const int algo = tests[i].algorithm;
118118
const int len = tests[i].digest_length;
119119

120+
memset(buf, 0, sizeof(buf));
120121
snprintf(buf, sizeof(buf), fmt, algo + 0x30, len * 2, hex);
121122
code = parse_digest(buf);
122123
assert_int_equal(code, tests[i].code);
123124

125+
memset(buf, 0, sizeof(buf));
124126
snprintf(buf, sizeof(buf), hex_fmt, 4 + len, algo + 0x30, len * 2, hex);
125127
code = parse_digest(buf);
126128
assert_int_equal(code, tests[i].code);

tests/syntax.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ static int32_t parse_as_include(const char *text, size_t *count)
623623
char dummy[16];
624624
int length = snprintf(dummy, sizeof(dummy), "$INCLUDE \"%s\"\n", path);
625625
assert_true(length > 0 && length < INT_MAX - ZONE_BLOCK_SIZE);
626-
char *include = malloc((size_t)length + 1 + ZONE_BLOCK_SIZE);
626+
char *include = calloc((size_t)length + 1 + ZONE_BLOCK_SIZE, 1);
627627
assert_non_null(include);
628628
(void)snprintf(include, (size_t)length + 1, "$INCLUDE \"%s\"\n", path);
629629
code = parse(include, count);
@@ -782,7 +782,7 @@ void bad_includes(void **state)
782782
char dummy[32];
783783
int length = snprintf(dummy, sizeof(dummy), "$INCLUDE \"%s\" foo. bar\n", path);
784784
assert_true(length > 0 && length < INT_MAX - ZONE_BLOCK_SIZE);
785-
char *include = malloc((size_t)length + 1 + ZONE_BLOCK_SIZE);
785+
char *include = calloc((size_t)length + 1 + ZONE_BLOCK_SIZE, 1);
786786
assert_non_null(include);
787787
(void)snprintf(include, (size_t)length + 1, "$INCLUDE \"%s\" foo. bar.\n", path);
788788
int result = fputs(include, handle);
@@ -834,7 +834,7 @@ void include_with_origin(void **state)
834834
char dummy[32];
835835
int length = snprintf(dummy, sizeof(dummy), "$INCLUDE \"%s\" baz.", path);
836836
assert_true(length > 0 && length < INT_MAX - ZONE_BLOCK_SIZE);
837-
char *include = malloc((size_t)length + 1 + ZONE_BLOCK_SIZE);
837+
char *include = calloc((size_t)length + 1 + ZONE_BLOCK_SIZE, 1);
838838
assert_non_null(include);
839839
(void)snprintf(include, (size_t)length + 1, "$INCLUDE \"%s\" baz.", path);
840840

@@ -899,7 +899,7 @@ void include_without_origin(void **state)
899899
#define FMT "$INCLUDE \"%s\""
900900
int length = snprintf(dummy, sizeof(dummy), "$INCLUDE \"%s\"", path);
901901
assert_true(length > 0 && length < INT_MAX - ZONE_BLOCK_SIZE);
902-
char *include = malloc((size_t)length + 1 + ZONE_BLOCK_SIZE);
902+
char *include = calloc((size_t)length + 1 + ZONE_BLOCK_SIZE, 1);
903903
assert_non_null(include);
904904
(void)snprintf(include, (size_t)length + 1, "$INCLUDE \"%s\"", path);
905905
#undef FMT
@@ -983,7 +983,7 @@ void owner_is_reinstated(void **state)
983983
" TXT foobar"
984984
int length = snprintf(dummy, sizeof(dummy), FMT, path);
985985
assert_true(length > 0 && length < INT_MAX - ZONE_BLOCK_SIZE);
986-
char *include = malloc((size_t)length + 1 + ZONE_BLOCK_SIZE);
986+
char *include = calloc((size_t)length + 1 + ZONE_BLOCK_SIZE, 1);
987987
assert_non_null(include);
988988
(void)snprintf(include, (size_t)length + 1, FMT, path);
989989
#undef FMT
@@ -1026,7 +1026,7 @@ void origin_is_reinstated(void **state)
10261026
"foo TXT foobar"
10271027
int length = snprintf(dummy, sizeof(dummy), FMT, path);
10281028
assert_true(length > 0 && length < INT_MAX - ZONE_BLOCK_SIZE);
1029-
char *include = malloc((size_t)length + 1 + ZONE_BLOCK_SIZE);
1029+
char *include = calloc((size_t)length + 1 + ZONE_BLOCK_SIZE, 1);
10301030
assert_non_null(include);
10311031
(void)snprintf(include, (size_t)length + 1, FMT, path);
10321032
#undef FMT

tests/time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void time_stamp_syntax(void **state)
9797
" J5D6fwFm8nN+6pBzeDQfsS3Ap3o= )"
9898

9999
size_t size = strlen(FORMAT) + strlen(tests[i].timestamp) + ZONE_BLOCK_SIZE + 1;
100-
char *rr = malloc((size_t)size + 1);
100+
char *rr = calloc((size_t)size + 1, 1);
101101
(void)snprintf(rr, size, FORMAT, tests[i].timestamp);
102102

103103
fprintf(stderr, "INPUT: %s\n", rr);

tests/ttl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void correct_ttl_is_used(void **state)
7878
char *str = malloc(len + ZONE_BLOCK_SIZE + 1);
7979
assert_non_null(str);
8080
memcpy(str, tests[i].str, len + 1);
81+
memset(str+len+1, 0, ZONE_BLOCK_SIZE);
8182

8283
zone_parser_t parser;
8384
zone_name_buffer_t name;
@@ -141,6 +142,7 @@ void correct_ttl_is_used_in_include(void **state)
141142
char *str = malloc((size_t)len + ZONE_BLOCK_SIZE + 1);
142143
assert_non_null(str);
143144
(void)snprintf(str, (size_t)len + 1, tests[i].fmt, inc);
145+
memset(str+len+1, 0, ZONE_BLOCK_SIZE);
144146

145147
FILE *handle = fopen(inc, "wb");
146148
assert_non_null(handle);

0 commit comments

Comments
 (0)