aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/src
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2015-11-04 10:40:21 +0100
committerHans Nilsson <[email protected]>2015-11-04 10:40:21 +0100
commit4f085471fc4e1886bd7549cf135e7038a87e6a8e (patch)
tree749d5796248b5eb08cbb74d1a413ff79ca1843f4 /lib/ssh/src
parent82393fda2f44841663b23c95879212f339a56474 (diff)
parenta541756c4ab173a63969f1789f82b56d22b00fa2 (diff)
downloadotp-4f085471fc4e1886bd7549cf135e7038a87e6a8e.tar.gz
otp-4f085471fc4e1886bd7549cf135e7038a87e6a8e.tar.bz2
otp-4f085471fc4e1886bd7549cf135e7038a87e6a8e.zip
Merge branch 'hans/ssh/bad_lengths_tests/OTP-12792' into maint
Diffstat (limited to 'lib/ssh/src')
-rw-r--r--lib/ssh/src/ssh_transport.erl13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/ssh/src/ssh_transport.erl b/lib/ssh/src/ssh_transport.erl
index 8b65806dc6..d622ec27fc 100644
--- a/lib/ssh/src/ssh_transport.erl
+++ b/lib/ssh/src/ssh_transport.erl
@@ -45,7 +45,7 @@
handle_kex_ecdh_init/2,
handle_kex_ecdh_reply/2,
extract_public_key/1,
- unpack/3, decompress/2, ssh_packet/2, pack/2, msg_data/1,
+ unpack/3, decompress/2, ssh_packet/2, pack/2, pack/3, msg_data/1,
sign/3, verify/4]).
%%%----------------------------------------------------------------------------
@@ -929,11 +929,18 @@ ssh_packet(Msg, Ssh) ->
BinMsg = ssh_message:encode(Msg),
pack(BinMsg, Ssh).
+pack(Data, Ssh=#ssh{}) ->
+ pack(Data, Ssh, 0).
+
+%%% Note: pack/3 is only to be called from tests that wants
+%%% to deliberetly send packets with wrong PacketLength!
+%%% Use pack/2 for all other purposes!
pack(Data0, #ssh{encrypt_block_size = BlockSize,
send_sequence = SeqNum, send_mac = MacAlg,
send_mac_key = MacKey,
random_length_padding = RandomLengthPadding}
- = Ssh0) when is_binary(Data0) ->
+ = Ssh0,
+ PacketLenDeviationForTests) when is_binary(Data0) ->
{Ssh1, Data} = compress(Ssh0, Data0),
PL = (BlockSize - ((4 + 1 + size(Data)) rem BlockSize)) rem BlockSize,
MinPaddingLen = if PL < 4 -> PL + BlockSize;
@@ -946,7 +953,7 @@ pack(Data0, #ssh{encrypt_block_size = BlockSize,
end,
PaddingLen = MinPaddingLen + ExtraPaddingLen,
Padding = ssh_bits:random(PaddingLen),
- PacketLen = 1 + PaddingLen + size(Data),
+ PacketLen = 1 + PaddingLen + size(Data) + PacketLenDeviationForTests,
PacketData = <<?UINT32(PacketLen),?BYTE(PaddingLen),
Data/binary, Padding/binary>>,
{Ssh2, EncPacket} = encrypt(Ssh1, PacketData),