77 * https://www.openssl.org/source/license.html
88 */
99
10- #include <stdio.h>
1110#include "internal/cryptlib.h"
12- #include <openssl/asn1.h>
1311#include <openssl/asn1t.h>
14- #include <openssl/conf.h>
1512#include <openssl/x509v3.h>
16- #include "ext_dat.h"
17- #include "x509_local.h"
18- #include "crypto/asn1.h"
1913
20- static int i2r_OBJECT_DIGEST_INFO (X509V3_EXT_METHOD * method ,
21- OBJECT_DIGEST_INFO * odi ,
22- BIO * out , int indent );
2314static int i2r_TARGET_CERT (X509V3_EXT_METHOD * method ,
2415 TARGET_CERT * tc ,
2516 BIO * out , int indent );
@@ -93,26 +84,40 @@ static int i2r_OBJECT_DIGEST_INFO(X509V3_EXT_METHOD *method,
9384 }
9485 switch (dot ) {
9586 case (ODI_TYPE_PUBLIC_KEY ):
96- BIO_printf (out , "%*sDigest Type: Public Key\n" , indent , "" );
87+ if (BIO_printf (out , "%*sDigest Type: Public Key\n" , indent , "" ) <= 0 ) {
88+ return 0 ;
89+ }
9790 break ;
9891 case (ODI_TYPE_PUBLIC_KEY_CERT ):
99- BIO_printf (out , "%*sDigest Type: Public Key Certificate\n" , indent , "" );
92+ if (BIO_printf (out , "%*sDigest Type: Public Key Certificate\n" , indent , "" ) <= 0 ) {
93+ return 0 ;
94+ }
10095 break ;
10196 case (ODI_TYPE_OTHER ): {
102- BIO_printf (out , "%*sDigest Type: Other\n" , indent , "" );
97+ if (BIO_printf (out , "%*sDigest Type: Other\n" , indent , "" ) <= 0 ) {
98+ return 0 ;
99+ }
103100 break ;
104101 }
105102 }
106103 if (odi -> otherObjectTypeID != NULL ) {
107- BIO_printf (out , "%*sDigest Type Identifier: " , indent , "" );
108- i2a_ASN1_OBJECT (out , odi -> otherObjectTypeID );
109- BIO_puts (out , "\n" );
104+ if (BIO_printf (out , "%*sDigest Type Identifier: " , indent , "" ) <= 0 ) {
105+ return 0 ;
106+ }
107+ if (i2a_ASN1_OBJECT (out , odi -> otherObjectTypeID ) <= 0 ) {
108+ return 0 ;
109+ }
110+ if (BIO_puts (out , "\n" ) <= 0 ) {
111+ return 0 ;
112+ }
110113 }
111114 if (BIO_printf (out , "%*sSignature Algorithm: " , indent , "" ) <= 0 )
112115 return 0 ;
113116 if (i2a_ASN1_OBJECT (out , odi -> digestAlgorithm -> algorithm ) <= 0 )
114117 return 0 ;
115- BIO_puts (out , "\n" );
118+ if (BIO_puts (out , "\n" ) <= 0 ) {
119+ return 0 ;
120+ }
116121 if (BIO_printf (out , "\n%*sSignature Value: " , indent , "" ) <= 0 )
117122 return 0 ;
118123 sig_nid = OBJ_obj2nid (odi -> digestAlgorithm -> algorithm );
@@ -125,7 +130,7 @@ static int i2r_OBJECT_DIGEST_INFO(X509V3_EXT_METHOD *method,
125130 return ameth -> sig_print (out , digalg , sig , indent + 4 , 0 );
126131 }
127132 }
128- if (BIO_write (out , "\n" , 1 ) != 1 )
133+ if (BIO_write (out , "\n" , 1 ) <= 0 )
129134 return 0 ;
130135 if (sig )
131136 return X509_signature_dump (out , sig , indent + 4 );
@@ -136,23 +141,38 @@ static int i2r_TARGET_CERT(X509V3_EXT_METHOD *method,
136141 TARGET_CERT * tc ,
137142 BIO * out , int indent )
138143{
139- BIO_printf (out , "%*s" , indent , "" );
144+ if (BIO_printf (out , "%*s" , indent , "" ) <= 0 ) {
145+ return 0 ;
146+ }
140147 if (tc -> targetCertificate != NULL ) {
141- BIO_puts (out , "Target Certificate:\n" );
142- i2r_ISSUER_SERIAL (method , tc -> targetCertificate , out , indent + 2 );
148+ if (BIO_puts (out , "Target Certificate:\n" ) <= 0 ) {
149+ return 0 ;
150+ }
151+ if (i2r_ISSUER_SERIAL (method , tc -> targetCertificate , out , indent + 2 ) <= 0 ) {
152+ return 0 ;
153+ }
143154 }
144155 if (tc -> targetName != NULL ) {
145156 // BIO_puts(out, "Target Name: ");
146- BIO_printf (out , "%*sTarget Name: " , indent , "" );
147- GENERAL_NAME_print (out , tc -> targetName );
148- BIO_puts (out , "\n" );
157+ if (BIO_printf (out , "%*sTarget Name: " , indent , "" ) <= 0 ) {
158+ return 0 ;
159+ }
160+ if (GENERAL_NAME_print (out , tc -> targetName ) <= 0 ) {
161+ return 0 ;
162+ }
163+ if (BIO_puts (out , "\n" ) <= 0 ) {
164+ return 0 ;
165+ }
149166 }
150167 if (tc -> certDigestInfo != NULL ) {
151- BIO_printf (out , "%*sCertificate Digest Info:\n" , indent , "" );
152- i2r_OBJECT_DIGEST_INFO (method , tc -> certDigestInfo , out , indent + 2 );
168+ if (BIO_printf (out , "%*sCertificate Digest Info:\n" , indent , "" ) <= 0 ) {
169+ return 0 ;
170+ }
171+ if (i2r_OBJECT_DIGEST_INFO (method , tc -> certDigestInfo , out , indent + 2 ) <= 0 ) {
172+ return 0 ;
173+ }
153174 }
154- BIO_puts (out , "\n" );
155- return 1 ;
175+ return BIO_puts (out , "\n" );
156176}
157177
158178static int i2r_TARGET (X509V3_EXT_METHOD * method ,
@@ -161,19 +181,26 @@ static int i2r_TARGET(X509V3_EXT_METHOD *method,
161181{
162182 switch (target -> type ) {
163183 case (TGT_TARGET_NAME ):
164- BIO_printf (out , "%*sTarget Name: " , indent , "" );
165- GENERAL_NAME_print (out , target -> choice .targetName );
166- BIO_puts (out , "\n" );
167- break ;
184+ if (BIO_printf (out , "%*sTarget Name: " , indent , "" ) <= 0 ) {
185+ return 0 ;
186+ }
187+ if (GENERAL_NAME_print (out , target -> choice .targetName ) <= 0 ) {
188+ return 0 ;
189+ }
190+ return BIO_puts (out , "\n" );
168191 case (TGT_TARGET_GROUP ):
169- BIO_printf (out , "%*sTarget Group: " , indent , "" );
170- GENERAL_NAME_print (out , target -> choice .targetGroup );
171- BIO_puts (out , "\n" );
172- break ;
192+ if (BIO_printf (out , "%*sTarget Group: " , indent , "" ) <= 0 ) {
193+ return 0 ;
194+ }
195+ if (GENERAL_NAME_print (out , target -> choice .targetGroup ) <= 0 ) {
196+ return 0 ;
197+ }
198+ return BIO_puts (out , "\n" );
173199 case (TGT_TARGET_CERT ):
174- BIO_printf (out , "%*sTarget Cert:\n" , indent , "" );
175- i2r_TARGET_CERT (method , target -> choice .targetCert , out , indent + 2 );
176- break ;
200+ if (BIO_printf (out , "%*sTarget Cert:\n" , indent , "" ) <= 0 ) {
201+ return 0 ;
202+ }
203+ return i2r_TARGET_CERT (method , target -> choice .targetCert , out , indent + 2 );
177204 }
178205 return 1 ;
179206}
@@ -185,9 +212,13 @@ static int i2r_TARGETS(X509V3_EXT_METHOD *method,
185212 int i ;
186213 TARGET * target ;
187214 for (i = 0 ; i < sk_TARGET_num (targets ); i ++ ) {
188- BIO_printf (out , "%*sTarget:\n" , indent , "" );
215+ if (BIO_printf (out , "%*sTarget:\n" , indent , "" ) <= 0 ) {
216+ return 0 ;
217+ }
189218 target = sk_TARGET_value (targets , i );
190- i2r_TARGET (method , target , out , indent + 2 );
219+ if (i2r_TARGET (method , target , out , indent + 2 ) <= 0 ) {
220+ return 0 ;
221+ }
191222 }
192223 return 1 ;
193224}
@@ -199,9 +230,13 @@ static int i2r_TARGETING_INFORMATION(X509V3_EXT_METHOD *method,
199230 int i ;
200231 TARGETS * targets ;
201232 for (i = 0 ; i < sk_TARGETS_num (tinfo ); i ++ ) {
202- BIO_printf (out , "%*sTargets:\n" , indent , "" );
233+ if (BIO_printf (out , "%*sTargets:\n" , indent , "" ) <= 0 ) {
234+ return 0 ;
235+ }
203236 targets = sk_TARGETS_value (tinfo , i );
204- i2r_TARGETS (method , targets , out , indent + 2 );
237+ if (i2r_TARGETS (method , targets , out , indent + 2 ) <= 0 ) {
238+ return 0 ;
239+ }
205240 }
206241 return 1 ;
207242}
0 commit comments