Skip to content

Commit 0bfe1e7

Browse files
committed
Make sure the other conn end not closed before using it
1 parent 5810907 commit 0bfe1e7

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/protoautossl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,6 @@ protoautossl_bev_readcb_srvdst(struct bufferevent *bev, pxy_conn_ctx_t *ctx)
441441
{
442442
log_finest_va("ENTER, size=%zu", evbuffer_get_length(bufferevent_get_input(bev)));
443443

444-
#ifndef WITHOUT_USERAUTH
445-
if (prototcp_try_send_userauth_msg(ctx->src.bev, ctx)) {
446-
return;
447-
}
448-
#endif /* !WITHOUT_USERAUTH */
449-
450444
// @todo We should validate the response from the server to protect the client,
451445
// as we do with the smtp protocol, @see protosmtp_bev_readcb_srvdst()
452446

@@ -455,6 +449,12 @@ protoautossl_bev_readcb_srvdst(struct bufferevent *bev, pxy_conn_ctx_t *ctx)
455449
return;
456450
}
457451

452+
#ifndef WITHOUT_USERAUTH
453+
if (prototcp_try_send_userauth_msg(ctx->src.bev, ctx)) {
454+
return;
455+
}
456+
#endif /* !WITHOUT_USERAUTH */
457+
458458
evbuffer_add_buffer(bufferevent_get_output(ctx->src.bev), bufferevent_get_input(bev));
459459
ctx->protoctx->set_watermarkcb(bev, ctx, ctx->src.bev);
460460
}

src/protosmtp.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,18 @@ protosmtp_bev_readcb_srvdst(struct bufferevent *bev, pxy_conn_ctx_t *ctx)
182182
{
183183
log_finest_va("ENTER, size=%zu", evbuffer_get_length(bufferevent_get_input(bev)));
184184

185+
// TODO: Do we need to check src.bev here?
185186
// Make sure src.bev exists
186187
if (!ctx->src.bev) {
187188
log_finest("src.bev does not exist");
188189
return;
189190
}
190191

192+
if (ctx->src.closed) {
193+
ctx->protoctx->discard_inbufcb(bev);
194+
return;
195+
}
196+
191197
#ifndef WITHOUT_USERAUTH
192198
if (prototcp_try_send_userauth_msg(ctx->src.bev, ctx)) {
193199
return;
@@ -206,11 +212,6 @@ protosmtp_bev_readcb_srvdst(struct bufferevent *bev, pxy_conn_ctx_t *ctx)
206212
return;
207213
}
208214

209-
if (ctx->src.closed) {
210-
ctx->protoctx->discard_inbufcb(bev);
211-
return;
212-
}
213-
214215
evbuffer_add_buffer(outbuf, inbuf);
215216
ctx->protoctx->set_watermarkcb(bev, ctx, ctx->src.bev);
216217
}

0 commit comments

Comments
 (0)