Skip to content

Commit aa51795

Browse files
author
Erlang/OTP
committed
Merge branch 'kuba/ssh/file_handle_size_limit/OTP-19748' into maint-27
* kuba/ssh/file_handle_size_limit/OTP-19748: ssh: code formatting ssh: verify file handle size limit for client data
2 parents 43b9064 + ef4e1cb commit aa51795

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
@@ -272,14 +272,25 @@ handle_data(Type, ChannelId, Data0, State = #state{pending = Pending}) ->
272272
handle_data(Type, ChannelId, Data, State#state{pending = <<>>})
273273
end.
274274

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

456467
handle_op(?SSH_FXP_RENAME, ReqId,
457-
Bin = <<?UINT32(PLen), _:PLen/binary, ?UINT32(PLen2),
458-
_:PLen2/binary>>,
468+
Bin = <<?UINT32(PLen), _:PLen/binary, ?UINT32(PLen2), _:PLen2/binary>>,
459469
State = #state{xf = #ssh_xfer{vsn = Vsn}}) when Vsn==3; Vsn==4 ->
460470
handle_op(?SSH_FXP_RENAME, ReqId, <<Bin/binary, 0:32>>, State);
461471

462472
handle_op(?SSH_FXP_RENAME, ReqId,
463-
<<?UINT32(PLen), BPath:PLen/binary, ?UINT32(PLen2),
464-
BPath2:PLen2/binary, ?UINT32(Flags)>>,
473+
<<?UINT32(PLen), BPath:PLen/binary, ?UINT32(PLen2), BPath2:PLen2/binary, ?UINT32(Flags)>>,
465474
State0 = #state{file_handler = FileMod, file_state = FS0}) ->
466475
Path = relate_file_name(BPath, State0),
467476
Path2 = relate_file_name(BPath2, State0),

0 commit comments

Comments
 (0)