diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/bio_asn1.c')
-rw-r--r-- | src/lib/libcrypto/asn1/bio_asn1.c | 59 |
1 files changed, 24 insertions, 35 deletions
diff --git a/src/lib/libcrypto/asn1/bio_asn1.c b/src/lib/libcrypto/asn1/bio_asn1.c index a6ad850e46..8ebac02a00 100644 --- a/src/lib/libcrypto/asn1/bio_asn1.c +++ b/src/lib/libcrypto/asn1/bio_asn1.c | |||
@@ -210,20 +210,18 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
210 | wrlen = 0; | 210 | wrlen = 0; |
211 | ret = -1; | 211 | ret = -1; |
212 | 212 | ||
213 | for(;;) | 213 | for(;;) { |
214 | { | 214 | switch (ctx->state) { |
215 | switch (ctx->state) | ||
216 | { | ||
217 | 215 | ||
218 | /* Setup prefix data, call it */ | 216 | /* Setup prefix data, call it */ |
219 | case ASN1_STATE_START: | 217 | case ASN1_STATE_START: |
220 | if (!asn1_bio_setup_ex(b, ctx, ctx->prefix, | 218 | if (!asn1_bio_setup_ex(b, ctx, ctx->prefix, |
221 | ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER)) | 219 | ASN1_STATE_PRE_COPY, ASN1_STATE_HEADER)) |
222 | return 0; | 220 | return 0; |
223 | break; | 221 | break; |
224 | 222 | ||
225 | /* Copy any pre data first */ | 223 | /* Copy any pre data first */ |
226 | case ASN1_STATE_PRE_COPY: | 224 | case ASN1_STATE_PRE_COPY: |
227 | 225 | ||
228 | ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free, | 226 | ret = asn1_bio_flush_ex(b, ctx, ctx->prefix_free, |
229 | ASN1_STATE_HEADER); | 227 | ASN1_STATE_HEADER); |
@@ -233,7 +231,7 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
233 | 231 | ||
234 | break; | 232 | break; |
235 | 233 | ||
236 | case ASN1_STATE_HEADER: | 234 | case ASN1_STATE_HEADER: |
237 | ctx->buflen = | 235 | ctx->buflen = |
238 | ASN1_object_size(0, inl, ctx->asn1_tag) - inl; | 236 | ASN1_object_size(0, inl, ctx->asn1_tag) - inl; |
239 | OPENSSL_assert(ctx->buflen <= ctx->bufsize); | 237 | OPENSSL_assert(ctx->buflen <= ctx->bufsize); |
@@ -245,7 +243,7 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
245 | 243 | ||
246 | break; | 244 | break; |
247 | 245 | ||
248 | case ASN1_STATE_HEADER_COPY: | 246 | case ASN1_STATE_HEADER_COPY: |
249 | ret = BIO_write(b->next_bio, | 247 | ret = BIO_write(b->next_bio, |
250 | ctx->buf + ctx->bufpos, ctx->buflen); | 248 | ctx->buf + ctx->bufpos, ctx->buflen); |
251 | if (ret <= 0) | 249 | if (ret <= 0) |
@@ -254,15 +252,14 @@ static int asn1_bio_write(BIO *b, const char *in , int inl) | |||
254 | ctx->buflen -= ret; | 252 | ctx->buflen -= ret; |
255 | if (ctx->buflen) | 253 | if (ctx->buflen) |
256 | ctx->bufpos += ret; | 254 | ctx->bufpos += ret; |
257 | else | 255 | else { |
258 | { | ||
259 | ctx->bufpos = 0; | 256 | ctx->bufpos = 0; |
260 | ctx->state = ASN1_STATE_DATA_COPY; | 257 | ctx->state = ASN1_STATE_DATA_COPY; |
261 | } | 258 | } |
262 | 259 | ||
263 | break; | 260 | break; |
264 | 261 | ||
265 | case ASN1_STATE_DATA_COPY: | 262 | case ASN1_STATE_DATA_COPY: |
266 | 263 | ||
267 | if (inl > ctx->copylen) | 264 | if (inl > ctx->copylen) |
268 | wrmax = ctx->copylen; | 265 | wrmax = ctx->copylen; |
@@ -306,8 +303,7 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | |||
306 | int ret; | 303 | int ret; |
307 | if (ctx->ex_len <= 0) | 304 | if (ctx->ex_len <= 0) |
308 | return 1; | 305 | return 1; |
309 | for(;;) | 306 | for(;;) { |
310 | { | ||
311 | ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, | 307 | ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, |
312 | ctx->ex_len); | 308 | ctx->ex_len); |
313 | if (ret <= 0) | 309 | if (ret <= 0) |
@@ -315,8 +311,7 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | |||
315 | ctx->ex_len -= ret; | 311 | ctx->ex_len -= ret; |
316 | if (ctx->ex_len > 0) | 312 | if (ctx->ex_len > 0) |
317 | ctx->ex_pos += ret; | 313 | ctx->ex_pos += ret; |
318 | else | 314 | else { |
319 | { | ||
320 | if(cleanup) | 315 | if(cleanup) |
321 | cleanup(b, &ctx->ex_buf, &ctx->ex_len, | 316 | cleanup(b, &ctx->ex_buf, &ctx->ex_len, |
322 | &ctx->ex_arg); | 317 | &ctx->ex_arg); |
@@ -333,8 +328,7 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, | |||
333 | asn1_bio_state_t ex_state, | 328 | asn1_bio_state_t ex_state, |
334 | asn1_bio_state_t other_state) | 329 | asn1_bio_state_t other_state) |
335 | { | 330 | { |
336 | if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) | 331 | if (setup && !setup(b, &ctx->ex_buf, &ctx->ex_len, &ctx->ex_arg)) { |
337 | { | ||
338 | BIO_clear_retry_flags(b); | 332 | BIO_clear_retry_flags(b); |
339 | return 0; | 333 | return 0; |
340 | } | 334 | } |
@@ -378,55 +372,52 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | |||
378 | ctx = (BIO_ASN1_BUF_CTX *) b->ptr; | 372 | ctx = (BIO_ASN1_BUF_CTX *) b->ptr; |
379 | if (ctx == NULL) | 373 | if (ctx == NULL) |
380 | return 0; | 374 | return 0; |
381 | switch(cmd) | 375 | switch(cmd) { |
382 | { | ||
383 | 376 | ||
384 | case BIO_C_SET_PREFIX: | 377 | case BIO_C_SET_PREFIX: |
385 | ex_func = arg2; | 378 | ex_func = arg2; |
386 | ctx->prefix = ex_func->ex_func; | 379 | ctx->prefix = ex_func->ex_func; |
387 | ctx->prefix_free = ex_func->ex_free_func; | 380 | ctx->prefix_free = ex_func->ex_free_func; |
388 | break; | 381 | break; |
389 | 382 | ||
390 | case BIO_C_GET_PREFIX: | 383 | case BIO_C_GET_PREFIX: |
391 | ex_func = arg2; | 384 | ex_func = arg2; |
392 | ex_func->ex_func = ctx->prefix; | 385 | ex_func->ex_func = ctx->prefix; |
393 | ex_func->ex_free_func = ctx->prefix_free; | 386 | ex_func->ex_free_func = ctx->prefix_free; |
394 | break; | 387 | break; |
395 | 388 | ||
396 | case BIO_C_SET_SUFFIX: | 389 | case BIO_C_SET_SUFFIX: |
397 | ex_func = arg2; | 390 | ex_func = arg2; |
398 | ctx->suffix = ex_func->ex_func; | 391 | ctx->suffix = ex_func->ex_func; |
399 | ctx->suffix_free = ex_func->ex_free_func; | 392 | ctx->suffix_free = ex_func->ex_free_func; |
400 | break; | 393 | break; |
401 | 394 | ||
402 | case BIO_C_GET_SUFFIX: | 395 | case BIO_C_GET_SUFFIX: |
403 | ex_func = arg2; | 396 | ex_func = arg2; |
404 | ex_func->ex_func = ctx->suffix; | 397 | ex_func->ex_func = ctx->suffix; |
405 | ex_func->ex_free_func = ctx->suffix_free; | 398 | ex_func->ex_free_func = ctx->suffix_free; |
406 | break; | 399 | break; |
407 | 400 | ||
408 | case BIO_C_SET_EX_ARG: | 401 | case BIO_C_SET_EX_ARG: |
409 | ctx->ex_arg = arg2; | 402 | ctx->ex_arg = arg2; |
410 | break; | 403 | break; |
411 | 404 | ||
412 | case BIO_C_GET_EX_ARG: | 405 | case BIO_C_GET_EX_ARG: |
413 | *(void **)arg2 = ctx->ex_arg; | 406 | *(void **)arg2 = ctx->ex_arg; |
414 | break; | 407 | break; |
415 | 408 | ||
416 | case BIO_CTRL_FLUSH: | 409 | case BIO_CTRL_FLUSH: |
417 | if (!b->next_bio) | 410 | if (!b->next_bio) |
418 | return 0; | 411 | return 0; |
419 | 412 | ||
420 | /* Call post function if possible */ | 413 | /* Call post function if possible */ |
421 | if (ctx->state == ASN1_STATE_HEADER) | 414 | if (ctx->state == ASN1_STATE_HEADER) { |
422 | { | ||
423 | if (!asn1_bio_setup_ex(b, ctx, ctx->suffix, | 415 | if (!asn1_bio_setup_ex(b, ctx, ctx->suffix, |
424 | ASN1_STATE_POST_COPY, ASN1_STATE_DONE)) | 416 | ASN1_STATE_POST_COPY, ASN1_STATE_DONE)) |
425 | return 0; | 417 | return 0; |
426 | } | 418 | } |
427 | 419 | ||
428 | if (ctx->state == ASN1_STATE_POST_COPY) | 420 | if (ctx->state == ASN1_STATE_POST_COPY) { |
429 | { | ||
430 | ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free, | 421 | ret = asn1_bio_flush_ex(b, ctx, ctx->suffix_free, |
431 | ASN1_STATE_DONE); | 422 | ASN1_STATE_DONE); |
432 | if (ret <= 0) | 423 | if (ret <= 0) |
@@ -435,15 +426,14 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | |||
435 | 426 | ||
436 | if (ctx->state == ASN1_STATE_DONE) | 427 | if (ctx->state == ASN1_STATE_DONE) |
437 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); | 428 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); |
438 | else | 429 | else { |
439 | { | ||
440 | BIO_clear_retry_flags(b); | 430 | BIO_clear_retry_flags(b); |
441 | return 0; | 431 | return 0; |
442 | } | 432 | } |
443 | break; | 433 | break; |
444 | 434 | ||
445 | 435 | ||
446 | default: | 436 | default: |
447 | if (!b->next_bio) | 437 | if (!b->next_bio) |
448 | return 0; | 438 | return 0; |
449 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); | 439 | return BIO_ctrl(b->next_bio, cmd, arg1, arg2); |
@@ -468,8 +458,7 @@ static int asn1_bio_get_ex(BIO *b, int cmd, | |||
468 | BIO_ASN1_EX_FUNCS extmp; | 458 | BIO_ASN1_EX_FUNCS extmp; |
469 | int ret; | 459 | int ret; |
470 | ret = BIO_ctrl(b, cmd, 0, &extmp); | 460 | ret = BIO_ctrl(b, cmd, 0, &extmp); |
471 | if (ret > 0) | 461 | if (ret > 0) { |
472 | { | ||
473 | *ex_func = extmp.ex_func; | 462 | *ex_func = extmp.ex_func; |
474 | *ex_free_func = extmp.ex_free_func; | 463 | *ex_free_func = extmp.ex_free_func; |
475 | } | 464 | } |