summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2018-11-08 21:37:21 +0000
committerjsing <>2018-11-08 21:37:21 +0000
commit68aeecb3d50de0003bf88570d68a2f9631c3c6b3 (patch)
tree0767ae482fbc77179729be18da37a25f30ae41c0
parent282c11bdbc9506966def8e70d943547afeec3c63 (diff)
downloadopenbsd-68aeecb3d50de0003bf88570d68a2f9631c3c6b3.tar.gz
openbsd-68aeecb3d50de0003bf88570d68a2f9631c3c6b3.tar.bz2
openbsd-68aeecb3d50de0003bf88570d68a2f9631c3c6b3.zip
Use ASN1_TYPE_new()/ASN1_TYPE_free() to avoid leaking memory.
From Ben L <bobsayshilol at live dot co dot uk>.
-rw-r--r--src/regress/lib/libcrypto/asn1/asn1evp.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/regress/lib/libcrypto/asn1/asn1evp.c b/src/regress/lib/libcrypto/asn1/asn1evp.c
index d1870f9acc..64a3becc70 100644
--- a/src/regress/lib/libcrypto/asn1/asn1evp.c
+++ b/src/regress/lib/libcrypto/asn1/asn1evp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1evp.c,v 1.2 2017/12/09 14:34:09 jsing Exp $ */ 1/* $OpenBSD: asn1evp.c,v 1.3 2018/11/08 21:37:21 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2017 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2017 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -69,35 +69,38 @@ main(int argc, char **argv)
69{ 69{
70 unsigned char data[16]; 70 unsigned char data[16];
71 long num = TEST_NUM; 71 long num = TEST_NUM;
72 ASN1_TYPE *at = NULL;
72 int failed = 1; 73 int failed = 1;
73 ASN1_TYPE at;
74 int len; 74 int len;
75 75
76 memset(&at, 0, sizeof(at)); 76 if ((at = ASN1_TYPE_new()) == NULL) {
77 fprintf(stderr, "FAIL: ASN1_TYPE_new returned NULL\n");
78 goto done;
79 }
77 80
78 if (!ASN1_TYPE_set_int_octetstring(&at, num, test_octetstring, 81 if (!ASN1_TYPE_set_int_octetstring(at, num, test_octetstring,
79 sizeof(test_octetstring))) { 82 sizeof(test_octetstring))) {
80 fprintf(stderr, "FAIL: ASN1_TYPE_set_int_octetstring failed\n"); 83 fprintf(stderr, "FAIL: ASN1_TYPE_set_int_octetstring failed\n");
81 goto done; 84 goto done;
82 } 85 }
83 if (at.type != V_ASN1_SEQUENCE) { 86 if (at->type != V_ASN1_SEQUENCE) {
84 fprintf(stderr, "FAIL: not a V_ASN1_SEQUENCE (%i != %i)\n", 87 fprintf(stderr, "FAIL: not a V_ASN1_SEQUENCE (%i != %i)\n",
85 at.type, V_ASN1_SEQUENCE); 88 at->type, V_ASN1_SEQUENCE);
86 goto done; 89 goto done;
87 } 90 }
88 if (at.value.sequence->type != V_ASN1_OCTET_STRING) { 91 if (at->value.sequence->type != V_ASN1_OCTET_STRING) {
89 fprintf(stderr, "FAIL: not a V_ASN1_OCTET_STRING (%i != %i)\n", 92 fprintf(stderr, "FAIL: not a V_ASN1_OCTET_STRING (%i != %i)\n",
90 at.type, V_ASN1_OCTET_STRING); 93 at->type, V_ASN1_OCTET_STRING);
91 goto done; 94 goto done;
92 } 95 }
93 if (compare_data("sequence", at.value.sequence->data, 96 if (compare_data("sequence", at->value.sequence->data,
94 at.value.sequence->length, asn1_atios, sizeof(asn1_atios)) == -1) 97 at->value.sequence->length, asn1_atios, sizeof(asn1_atios)) == -1)
95 goto done; 98 goto done;
96 99
97 memset(&data, 0, sizeof(data)); 100 memset(&data, 0, sizeof(data));
98 num = 0; 101 num = 0;
99 102
100 if ((len = ASN1_TYPE_get_int_octetstring(&at, &num, data, 103 if ((len = ASN1_TYPE_get_int_octetstring(at, &num, data,
101 sizeof(data))) < 0) { 104 sizeof(data))) < 0) {
102 fprintf(stderr, "FAIL: ASN1_TYPE_get_int_octetstring failed\n"); 105 fprintf(stderr, "FAIL: ASN1_TYPE_get_int_octetstring failed\n");
103 goto done; 106 goto done;
@@ -118,7 +121,7 @@ main(int argc, char **argv)
118 num = 0; 121 num = 0;
119 122
120 /* With a limit buffer, the output should be truncated... */ 123 /* With a limit buffer, the output should be truncated... */
121 if ((len = ASN1_TYPE_get_int_octetstring(&at, &num, data, 4)) < 0) { 124 if ((len = ASN1_TYPE_get_int_octetstring(at, &num, data, 4)) < 0) {
122 fprintf(stderr, "FAIL: ASN1_TYPE_get_int_octetstring failed\n"); 125 fprintf(stderr, "FAIL: ASN1_TYPE_get_int_octetstring failed\n");
123 goto done; 126 goto done;
124 } 127 }
@@ -141,5 +144,7 @@ main(int argc, char **argv)
141 failed = 0; 144 failed = 0;
142 145
143 done: 146 done:
147 ASN1_TYPE_free(at);
148
144 return failed; 149 return failed;
145} 150}