Skip to content

Commit

Permalink
fix: check handle not NULL in quicer:recv with mutex
Browse files Browse the repository at this point in the history
It is just nice to call it to avoid unnecessary
return '{error, invalid_parameter}'
  • Loading branch information
qzhuyan committed Oct 11, 2023
1 parent dc72431 commit 702fac4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 6 additions & 0 deletions c_src/quicer_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,12 @@ recv2(ErlNifEnv *env, __unused_parm__ int argc, const ERL_NIF_TERM argv[])
TP_NIF_3(start, (uintptr_t)s_ctx->Stream, size_req);
enif_mutex_lock(s_ctx->lock);

if ( !s_ctx->Stream )
{
res = ERROR_TUPLE_2(ATOM_CLOSED);
goto Exit;
}

if (ACCEPTOR_RECV_MODE_PASSIVE != s_ctx->owner->active)
{
res = ERROR_TUPLE_2(ATOM_EINVAL);
Expand Down
3 changes: 1 addition & 2 deletions test/quicer_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ tc_stream_passive_receive_shutdown(Config) ->
{ok, <<"pong">>} = quicer:recv(Stm, 0),
case quicer:recv(Stm, 0) of
{error, peer_send_shutdown} -> ok;
{error, invalid_parameter} -> ok;
{error, closed} -> ok
end,
quicer:close_connection(Conn),
Expand Down Expand Up @@ -626,7 +625,7 @@ tc_stream_passive_receive_aborted(Config) ->
{ok, 5} = quicer:send(Stm, <<"Abort">>),
case quicer:recv(Stm, 0) of
{error, peer_send_aborted} -> ok;
{error, invalid_parameter} -> ok
{error, closed} -> ok
end,
quicer:close_connection(Conn),
SPid ! done,
Expand Down

0 comments on commit 702fac4

Please sign in to comment.