Skip to content

Commit 9334917

Browse files
committed
Merge branch 'kuba/ssh/file_handle_size_limit/OTP-19748' into maint
* kuba/ssh/file_handle_size_limit/OTP-19748: ssh: code formatting ssh: verify file handle size limit for client data
2 parents 99aaec9 + ef4e1cb commit 9334917

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/ssh/src/ssh_sftpd.erl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,25 @@ handle_data(Type, ChannelId, Data0, State = #state{pending = Pending}) ->
274274
handle_data(Type, ChannelId, Data, State#state{pending = <<>>})
275275
end.
276276

277+
%% From draft-ietf-secsh-filexfer-02 "The file handle strings MUST NOT be longer than 256 bytes."
278+
handle_op(Request, ReqId, <<?UINT32(HLen), _/binary>>, State = #state{xf = XF})
279+
when (Request == ?SSH_FXP_CLOSE orelse
280+
Request == ?SSH_FXP_FSETSTAT orelse
281+
Request == ?SSH_FXP_FSTAT orelse
282+
Request == ?SSH_FXP_READ orelse
283+
Request == ?SSH_FXP_READDIR orelse
284+
Request == ?SSH_FXP_WRITE),
285+
HLen > 256 ->
286+
ssh_xfer:xf_send_status(XF, ReqId, ?SSH_FX_INVALID_HANDLE, "Invalid handle"),
287+
State;
277288
handle_op(?SSH_FXP_INIT, Version, B, State) when is_binary(B) ->
278289
XF = State#state.xf,
279290
Vsn = lists:min([XF#ssh_xfer.vsn, Version]),
280291
XF1 = XF#ssh_xfer{vsn = Vsn},
281292
ssh_xfer:xf_send_reply(XF1, ?SSH_FXP_VERSION, <<?UINT32(Vsn)>>),
282293
State#state{xf = XF1};
283294
handle_op(?SSH_FXP_REALPATH, ReqId,
284-
<<?UINT32(Rlen), RPath:Rlen/binary>>,
295+
<<?UINT32(RLen), RPath:RLen/binary>>,
285296
State0) ->
286297
RelPath = relate_file_name(RPath, State0, _Canonicalize=false),
287298
{Res, State} = resolve_symlinks(RelPath, State0),
@@ -456,14 +467,12 @@ handle_op(?SSH_FXP_RMDIR, ReqId, <<?UINT32(PLen), BPath:PLen/binary>>,
456467
send_status(Status, ReqId, State1);
457468

458469
handle_op(?SSH_FXP_RENAME, ReqId,
459-
Bin = <<?UINT32(PLen), _:PLen/binary, ?UINT32(PLen2),
460-
_:PLen2/binary>>,
470+
Bin = <<?UINT32(PLen), _:PLen/binary, ?UINT32(PLen2), _:PLen2/binary>>,
461471
State = #state{xf = #ssh_xfer{vsn = Vsn}}) when Vsn==3; Vsn==4 ->
462472
handle_op(?SSH_FXP_RENAME, ReqId, <<Bin/binary, 0:32>>, State);
463473

464474
handle_op(?SSH_FXP_RENAME, ReqId,
465-
<<?UINT32(PLen), BPath:PLen/binary, ?UINT32(PLen2),
466-
BPath2:PLen2/binary, ?UINT32(Flags)>>,
475+
<<?UINT32(PLen), BPath:PLen/binary, ?UINT32(PLen2), BPath2:PLen2/binary, ?UINT32(Flags)>>,
467476
State0 = #state{file_handler = FileMod, file_state = FS0}) ->
468477
Path = relate_file_name(BPath, State0),
469478
Path2 = relate_file_name(BPath2, State0),

0 commit comments

Comments
 (0)