diff options
Diffstat (limited to 'src/lib/libcrypto/bio/b_sock.c')
-rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index e5f42398df..05eb362cc6 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c | |||
@@ -452,31 +452,7 @@ BIO_accept(int sock, char **addr) | |||
452 | char *p, *tmp; | 452 | char *p, *tmp; |
453 | 453 | ||
454 | struct { | 454 | struct { |
455 | /* | 455 | socklen_t len; |
456 | * As for following union. Trouble is that there are platforms | ||
457 | * that have socklen_t and there are platforms that don't, on | ||
458 | * some platforms socklen_t is int and on some size_t. So what | ||
459 | * one can do? One can cook #ifdef spaghetti, which is nothing | ||
460 | * but masochistic. Or one can do union between int and size_t. | ||
461 | * One naturally does it primarily for 64-bit platforms where | ||
462 | * sizeof(int) != sizeof(size_t). But would it work? Note that | ||
463 | * if size_t member is initialized to 0, then later int member | ||
464 | * assignment naturally does the job on little-endian platforms | ||
465 | * regardless accept's expectations! What about big-endians? | ||
466 | * If accept expects int*, then it works, and if size_t*, then | ||
467 | * length value would appear as unreasonably large. But this | ||
468 | * won't prevent it from filling in the address structure. The | ||
469 | * trouble of course would be if accept returns more data than | ||
470 | * actual buffer can accomodate and overwrite stack... That's | ||
471 | * where early OPENSSL_assert comes into picture. Besides, the | ||
472 | * only 64-bit big-endian platform found so far that expects | ||
473 | * size_t* is HP-UX, where stack grows towards higher address. | ||
474 | * <appro> | ||
475 | */ | ||
476 | union { | ||
477 | size_t s; | ||
478 | int i; | ||
479 | } len; | ||
480 | union { | 456 | union { |
481 | struct sockaddr sa; | 457 | struct sockaddr sa; |
482 | struct sockaddr_in sa_in; | 458 | struct sockaddr_in sa_in; |
@@ -484,15 +460,9 @@ BIO_accept(int sock, char **addr) | |||
484 | } from; | 460 | } from; |
485 | } sa; | 461 | } sa; |
486 | 462 | ||
487 | sa.len.s = 0; | 463 | sa.len = sizeof(sa.from); |
488 | sa.len.i = sizeof(sa.from); | ||
489 | memset(&sa.from, 0, sizeof(sa.from)); | 464 | memset(&sa.from, 0, sizeof(sa.from)); |
490 | ret = accept(sock, &sa.from.sa, (void *)&sa.len); | 465 | ret = accept(sock, &sa.from.sa, &sa.len); |
491 | if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) { | ||
492 | OPENSSL_assert(sa.len.s <= sizeof(sa.from)); | ||
493 | sa.len.i = (int)sa.len.s; | ||
494 | /* use sa.len.i from this point */ | ||
495 | } | ||
496 | if (ret == -1) { | 466 | if (ret == -1) { |
497 | if (BIO_sock_should_retry(ret)) | 467 | if (BIO_sock_should_retry(ret)) |
498 | return -2; | 468 | return -2; |
@@ -511,7 +481,7 @@ BIO_accept(int sock, char **addr) | |||
511 | static union { | 481 | static union { |
512 | void *p; | 482 | void *p; |
513 | int (*f)(const struct sockaddr *, | 483 | int (*f)(const struct sockaddr *, |
514 | size_t/*socklen_t*/, char *, size_t, | 484 | socklen_t, char *, size_t, |
515 | char *, size_t, int); | 485 | char *, size_t, int); |
516 | } p_getnameinfo = {NULL}; | 486 | } p_getnameinfo = {NULL}; |
517 | /* 2nd argument to getnameinfo is specified to | 487 | /* 2nd argument to getnameinfo is specified to |
@@ -527,7 +497,7 @@ BIO_accept(int sock, char **addr) | |||
527 | if (p_getnameinfo.p == (void *) - 1) | 497 | if (p_getnameinfo.p == (void *) - 1) |
528 | break; | 498 | break; |
529 | 499 | ||
530 | if ((*p_getnameinfo.f)(&sa.from.sa, sa.len.i, h, sizeof(h), | 500 | if ((*p_getnameinfo.f)(&sa.from.sa, sa.len, h, sizeof(h), |
531 | s, sizeof(s), NI_NUMERICHOST|NI_NUMERICSERV)) | 501 | s, sizeof(s), NI_NUMERICHOST|NI_NUMERICSERV)) |
532 | break; | 502 | break; |
533 | nl = strlen(h) + strlen(s) + 2; | 503 | nl = strlen(h) + strlen(s) + 2; |