Commit 1f0bb6c595ef5be0c950fdf38b765e9917114ab3

Authored by Perry Werneck
1 parent d04b76ae

Fixing segfault on CRL download.

Showing 1 changed file with 11 additions and 7 deletions   Show diff stats
src/ssl/crl.c
... ... @@ -179,7 +179,7 @@ int lib3270_crl_new_from_dist_points(H3270 *hSession, void *ssl_error, CRL_DIST_
179 179 // https://nougat.cablelabs.com/DLNA-RUI/openssl/commit/57912ed329f870b237f2fd9f2de8dec3477d1729
180 180 //
181 181 size_t ix;
182   - int i, gtype;
  182 + int i;
183 183  
184 184 lib3270_autoptr(LIB3270_STRING_ARRAY) uris = lib3270_string_array_new();
185 185  
... ... @@ -194,19 +194,23 @@ int lib3270_crl_new_from_dist_points(H3270 *hSession, void *ssl_error, CRL_DIST_
194 194  
195 195 for (i = 0; i < sk_GENERAL_NAME_num(gens); i++)
196 196 {
  197 + int gtype;
197 198 GENERAL_NAME *gen = sk_GENERAL_NAME_value(gens, i);
198 199 ASN1_STRING *uri = GENERAL_NAME_get0_value(gen, &gtype);
199   - if(uri)
  200 +
  201 + if(uri && gtype == GEN_URI)
200 202 {
  203 + int length = ASN1_STRING_length(uri);
  204 +
201 205 #if (OPENSSL_VERSION_NUMBER >= 0x10100000L) // OpenSSL 1.1.0+
202 206 const unsigned char * data = ASN1_STRING_get0_data(uri);
203 207 #else
204   - const unsigned char * data = ASN1_STRING_data(uri); // ASN1_STRING_get0_data(uri);
  208 + const unsigned char * data = ASN1_STRING_data(uri);
205 209 #endif // OpenSSL 1.1.0+
206   - if(data)
207   - {
208   - lib3270_string_array_append_with_length(uris,(char *) data, (size_t) ASN1_STRING_length(uri));
209   - }
  210 +
  211 + if(data && length > 0)
  212 + lib3270_string_array_append_with_length(uris,(char *) data, (size_t) length);
  213 +
210 214 }
211 215  
212 216 }
... ...