mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
Merge pull request #25537 from evverx/fuzz-resource-records
tests: fuzz dns resource records
This commit is contained in:
commit
cda7c31065
35
src/resolve/fuzz-resource-record.c
Normal file
35
src/resolve/fuzz-resource-record.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "fuzz.h"
|
||||
#include "memory-util.h"
|
||||
#include "resolved-dns-packet.h"
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_free_ char *out = NULL; /* out should be freed after f */
|
||||
size_t out_size;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL, *copy = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
|
||||
if (outside_size_range(size, 0, DNS_PACKET_SIZE_MAX))
|
||||
return 0;
|
||||
|
||||
if (dns_resource_record_new_from_raw(&rr, data, size) < 0)
|
||||
return 0;
|
||||
|
||||
assert_se(copy = dns_resource_record_copy(rr));
|
||||
assert_se(dns_resource_record_equal(copy, rr) > 0);
|
||||
|
||||
assert_se(f = open_memstream_unlocked(&out, &out_size));
|
||||
(void) fprintf(f, "%s", strna(dns_resource_record_to_string(rr)));
|
||||
|
||||
if (dns_resource_record_to_json(rr, &v) < 0)
|
||||
return 0;
|
||||
|
||||
(void) json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR|JSON_FORMAT_SOURCE, f, NULL);
|
||||
(void) dns_resource_record_to_wire_format(rr, false);
|
||||
(void) dns_resource_record_to_wire_format(rr, true);
|
||||
|
||||
return 0;
|
||||
}
|
@ -237,6 +237,11 @@ fuzzers += [
|
||||
libshared],
|
||||
[lib_openssl_or_gcrypt,
|
||||
libm]],
|
||||
[files('fuzz-resource-record.c'),
|
||||
[libsystemd_resolve_core,
|
||||
libshared],
|
||||
[lib_openssl_or_gcrypt,
|
||||
libm]],
|
||||
]
|
||||
|
||||
systemd_resolved_sources += files('resolved.c')
|
||||
|
@ -1137,12 +1137,15 @@ const char *dns_resource_record_to_string(DnsResourceRecord *rr) {
|
||||
break;
|
||||
|
||||
default:
|
||||
t = hexmem(rr->generic.data, rr->generic.data_size);
|
||||
if (!t)
|
||||
return NULL;
|
||||
|
||||
/* Format as documented in RFC 3597, Section 5 */
|
||||
r = asprintf(&s, "%s \\# %zu %s", k, rr->generic.data_size, t);
|
||||
if (rr->generic.data_size == 0)
|
||||
r = asprintf(&s, "%s \\# 0", k);
|
||||
else {
|
||||
t = hexmem(rr->generic.data, rr->generic.data_size);
|
||||
if (!t)
|
||||
return NULL;
|
||||
r = asprintf(&s, "%s \\# %zu %s", k, rr->generic.data_size, t);
|
||||
}
|
||||
if (r < 0)
|
||||
return NULL;
|
||||
break;
|
||||
|
BIN
test/fuzz/fuzz-resource-record/crash-type-bitmap-to-json
Normal file
BIN
test/fuzz/fuzz-resource-record/crash-type-bitmap-to-json
Normal file
Binary file not shown.
BIN
test/fuzz/fuzz-resource-record/ub-zero-length-rdata
Normal file
BIN
test/fuzz/fuzz-resource-record/ub-zero-length-rdata
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user