Skip to content

Commit

Permalink
make sure we have handling for IO errors
Browse files Browse the repository at this point in the history
Ensures that the MbedTLS state-machine gets a chance to handle them.
  • Loading branch information
vtjnash authored and quinnj committed Aug 3, 2022
1 parent 4ed38f6 commit b95ea81
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ssl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ function f_send(c_bio, buf, nbytes)
if !isopen(bio) || bio.status == Base.StatusClosing
return Cint(MBEDTLS_ERR_NET_CONN_RESET)
end
return Cint(unsafe_write(bio, buf, nbytes))
try
return Cint(unsafe_write(bio, buf, nbytes))
catch ex
ex isa Base.IOError && return Cint(MBEDTLS_ERR_NET_SEND_FAILED)
rethrow() # this may corrupt memory, lead to undefined behavior, or (hopefully) just be badly fatal
end
end


Expand Down Expand Up @@ -415,7 +420,7 @@ function f_recv(c_bio, buf, nbytes) # (Ptr{Cvoid}, Ptr{UInt8}, Csize_t)
eof(bio) && ( @🤖 "f_recv CONN_EOF";
return Cint(MBEDTLS_ERR_SSL_CONN_EOF))
catch ex ;@🤖 "f_recv RECV_FAILED"
ex isa IOError && return Cint(MBEDTLS_ERR_NET_RECV_FAILED)
ex isa Base.IOError && return Cint(MBEDTLS_ERR_NET_RECV_FAILED)
rethrow()
end
end
Expand Down

0 comments on commit b95ea81

Please sign in to comment.