Commit fc25d5e7 authored by Vasil Velichkov's avatar Vasil Velichkov Committed by Lev Walkin

Fix the memory leaks in check-42.c test

The asn_set_add calls realloc in some of the cases and the struct cannot
be freed correctly when the sub-structs are allocated on the stack
parent cef21e07
...@@ -90,26 +90,23 @@ buf_fill(const void *buffer, size_t size, void *app_key) { ...@@ -90,26 +90,23 @@ buf_fill(const void *buffer, size_t size, void *app_key) {
static void static void
check_serialize() { check_serialize() {
LogLine_t ll; LogLine_t ll;
VariablePartSet_t vps; VariablePartSet_t *vps;
VariablePart_t vp; VariablePart_t *vp;
VisibleString_t vpart; VisibleString_t *vpart;
asn_enc_rval_t erval; asn_enc_rval_t erval;
int i; int i;
memset(&ll, 0, sizeof(ll)); memset(&ll, 0, sizeof(ll));
memset(&vps, 0, sizeof(vps)); vps = calloc(1, sizeof(*vps));
memset(&vp, 0, sizeof(vp)); vp = calloc(1, sizeof(*vp));
memset(&vpart, 0, sizeof(vpart)); vpart = OCTET_STRING_new_fromBuf(&asn_DEF_VisibleString, "123", 3);
vpart.buf = (uint8_t *)"123";
vpart.size = 3; vp->present = VariablePart_PR_vset;
ASN_SET_ADD(&vp->choice.vset, vpart);
vp.present = VariablePart_PR_vset; vps->resolution.accept_as = accept_as_unknown;
ASN_SET_ADD(&vp.choice.vset, &vpart); ASN_SEQUENCE_ADD(&vps->vparts, vp);
vps.resolution.accept_as = accept_as_unknown; ASN_SEQUENCE_ADD(&ll.varsets, vps);
ASN_SEQUENCE_ADD(&vps.vparts, &vp); OCTET_STRING_fromBuf(&ll.line_digest, "zzz\007", 4);
ASN_SEQUENCE_ADD(&ll.varsets, &vps);
ll.line_digest.buf = (uint8_t *)"zzz\007";
ll.line_digest.size = 4;
asn_fprint(stderr, &asn_DEF_LogLine, &ll); asn_fprint(stderr, &asn_DEF_LogLine, &ll);
buf_size = 128; buf_size = 128;
...@@ -125,6 +122,8 @@ check_serialize() { ...@@ -125,6 +122,8 @@ check_serialize() {
fprintf(stderr, "\n\n"); fprintf(stderr, "\n\n");
assert(erval.encoded == sizeof(buf0)); assert(erval.encoded == sizeof(buf0));
assert(memcmp(buf0, buf, sizeof(buf0)) == 0); assert(memcmp(buf0, buf, sizeof(buf0)) == 0);
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LogLine, &ll);
return;
} }
#ifdef ENABLE_LIBFUZZER #ifdef ENABLE_LIBFUZZER
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment