Skip to content

Commit 86505a7

Browse files
authored
Avoid using PJ_EEOF to indicate SSL renegotiation (#4642)
1 parent 3cadcc8 commit 86505a7

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

pjlib/include/pj/errno.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ PJ_DECL(pj_status_t) pj_register_strerror(pj_status_t start_code,
492492
* Socket is stopped
493493
*/
494494
#define PJ_ESOCKETSTOP (PJ_ERRNO_START_STATUS + 24)/* 70024 */
495+
/**
496+
* @hideinitializer
497+
* Try again
498+
*/
499+
#define PJ_ETRYAGAIN (PJ_ERRNO_START_STATUS + 25)/* 70025 */
495500

496501
/** @} */ /* pj_errnum */
497502

pjlib/src/pj/errno.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ static const struct
7878
PJ_BUILD_ERR(PJ_EIPV6NOTSUP, "IPv6 is not supported"),
7979
PJ_BUILD_ERR(PJ_EAFNOTSUP, "Unsupported address family"),
8080
PJ_BUILD_ERR(PJ_EGONE, "Object no longer exists"),
81-
PJ_BUILD_ERR(PJ_ESOCKETSTOP, "Socket is in bad state")
81+
PJ_BUILD_ERR(PJ_ESOCKETSTOP, "Socket is in bad state"),
82+
PJ_BUILD_ERR(PJ_ETRYAGAIN, "Try again")
8283
};
8384
#endif /* PJ_HAS_ERROR_STRING */
8485

pjlib/src/pj/ssl_sock_gtls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ static pj_status_t ssl_read(pj_ssl_sock_t *ssock, void *data, int *size)
11941194
/* Nothing more to read */
11951195
return PJ_SUCCESS;
11961196
} else if (decrypted_size == GNUTLS_E_REHANDSHAKE) {
1197-
return PJ_EEOF;
1197+
return PJ_ETRYAGAIN;
11981198
} else if (decrypted_size == GNUTLS_E_AGAIN ||
11991199
decrypted_size == GNUTLS_E_INTERRUPTED ||
12001200
!gnutls_error_is_fatal(decrypted_size))

pjlib/src/pj/ssl_sock_imp_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ static pj_bool_t ssock_on_data_read (pj_ssl_sock_t *ssock,
854854

855855
} else if (status_ == PJ_SUCCESS) {
856856
break;
857-
} else if (status_ == PJ_EEOF) {
857+
} else if (status_ == PJ_ETRYAGAIN) {
858858
status = ssl_do_handshake(ssock);
859859
if (status == PJ_SUCCESS) {
860860
/* Renegotiation completed */
@@ -1817,7 +1817,7 @@ static pj_status_t ssl_send (pj_ssl_sock_t *ssock,
18171817
if (status == PJ_SUCCESS && nwritten == size) {
18181818
/* All data written, flush write buffer to network socket */
18191819
status = flush_circ_buf_output(ssock, send_key, size, flags);
1820-
} else if (status == PJ_EEOF) {
1820+
} else if (status == PJ_ETRYAGAIN) {
18211821
/* Re-negotiation is on progress, flush re-negotiation data */
18221822
status = flush_circ_buf_output(ssock, &ssock->handshake_op_key, 0, 0);
18231823
if (status == PJ_SUCCESS || status == PJ_EPENDING) {

pjlib/src/pj/ssl_sock_ossl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,10 +2487,10 @@ static pj_status_t ssl_read(pj_ssl_sock_t *ssock, void *data, int *size)
24872487
}
24882488
}
24892489

2490-
/* Return PJ_EEOF when SSL needs renegotiation */
2490+
/* Return PJ_ETRYAGAIN when SSL needs renegotiation */
24912491
if (!SSL_is_init_finished(ossock->ossl_ssl)) {
24922492
pj_lock_release(ssock->write_mutex);
2493-
return PJ_EEOF;
2493+
return PJ_ETRYAGAIN;
24942494
}
24952495
}
24962496

@@ -2518,9 +2518,9 @@ static pj_status_t ssl_write(pj_ssl_sock_t *ssock, const void *data,
25182518
int err;
25192519
err = SSL_get_error(ossock->ossl_ssl, *nwritten);
25202520
if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_NONE) {
2521-
status = PJ_EEOF;
2521+
status = PJ_ETRYAGAIN;
25222522
} else {
2523-
/* Some problem occured */
2523+
/* Some problem occurred */
25242524
status = STATUS_FROM_SSL_ERR2("Write", ssock, *nwritten,
25252525
err, size);
25262526
}

pjlib/src/pj/ssl_sock_schannel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,14 +1539,14 @@ static pj_status_t ssl_read(pj_ssl_sock_t* ssock, void* data, int* size)
15391539
/* Set SSL state as handshaking & reset handshake status */
15401540
ssock->ssl_state = SSL_STATE_HANDSHAKING;
15411541
ssock->handshake_status = PJ_EUNKNOWN;
1542-
status = PJ_EEOF;
1542+
status = PJ_ETRYAGAIN;
15431543
}
15441544

15451545
else if (ss == SEC_I_CONTEXT_EXPIRED)
15461546
{
15471547
PJ_LOG(3, (SNAME(ssock), "TLS connection closed"));
15481548
//status = sec_err_to_pj(ss);
1549-
status = PJ_ECANCELLED;
1549+
status = PJ_EEOF;
15501550
}
15511551

15521552
else {

0 commit comments

Comments
 (0)