From 32974ac4210b1fc84dab59c1e7279b998e20d4ac Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Tue, 2 Mar 2021 20:56:16 -0600 Subject: [PATCH] asn1: Fix leak in asn1_print --- lib/asn1/asn1_print.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/asn1/asn1_print.c b/lib/asn1/asn1_print.c index f0d3c3a15..652b23ba4 100644 --- a/lib/asn1/asn1_print.c +++ b/lib/asn1/asn1_print.c @@ -65,7 +65,7 @@ static unsigned long indefinite_form_loop_max = 10000; typedef int (*decoder)(const unsigned char *, size_t, void *, size_t *); typedef char *(*printer)(const void *, int); typedef void (*releaser)(void *); -struct types { +const struct types { const char *name; decoder decode; printer print; @@ -97,6 +97,8 @@ struct types { #include "x690sample_asn1_syms.x" }; +struct types sorted_types[sizeof(types)/sizeof(types[0])]; + static size_t loop (unsigned char *buf, size_t len, int indent) { @@ -350,7 +352,6 @@ type_cmp(const void *va, const void *vb) static int dotype(unsigned char *buf, size_t len, char **argv) { - struct types *sorted_types = emalloc(sizeof(types)); const char *typename; size_t matches = 0; size_t sz; @@ -397,12 +398,12 @@ dotype(unsigned char *buf, size_t len, char **argv) fprintf(stderr, "Match: %s\n", typename); else fprintf(stderr, "Prefix match: %s\n", typename); - s = sorted_types[i].print(v, - indent_flag ? ASN1_PRINT_INDENT : 0); + s = sorted_types[i].print(v, indent_flag ? ASN1_PRINT_INDENT : 0); sorted_types[i].release(v); if (!s) ret = errno; } + free(v); if (ret == 0) { fprintf(stdout, "%s\n", s); @@ -488,7 +489,6 @@ dotype(unsigned char *buf, size_t len, char **argv) err(1, "Could not decode and print data as type %s", typename); } } - free(buf); free(s); return 0; }