MCPcopy Create free account
hub / github.com/TigerVNC/tigervnc / read

Method read

java/com/jcraft/jsch/Session.java:914–1052  ·  view source on GitHub ↗
(Buffer buf)

Source from the content-addressed store, hash-verified

912 private int s2ccipher_size=8;
913 private int c2scipher_size=8;
914 public Buffer read(Buffer buf) throws Exception{
915 int j=0;
916 while(true){
917 buf.reset();
918 io.getByte(buf.buffer, buf.index, s2ccipher_size);
919 buf.index+=s2ccipher_size;
920 if(s2ccipher!=null){
921 s2ccipher.update(buf.buffer, 0, s2ccipher_size, buf.buffer, 0);
922 }
923 j=((buf.buffer[0]<<24)&0xff000000)|
924 ((buf.buffer[1]<<16)&0x00ff0000)|
925 ((buf.buffer[2]<< 8)&0x0000ff00)|
926 ((buf.buffer[3] )&0x000000ff);
927 // RFC 4253 6.1. Maximum Packet Length
928 if(j<5 || j>PACKET_MAX_SIZE){
929 start_discard(buf, s2ccipher, s2cmac, j, PACKET_MAX_SIZE);
930 }
931 int need = j+4-s2ccipher_size;
932 //if(need<0){
933 // throw new IOException("invalid data");
934 //}
935 if((buf.index+need)>buf.buffer.length){
936 byte[] foo=new byte[buf.index+need];
937 System.arraycopy(buf.buffer, 0, foo, 0, buf.index);
938 buf.buffer=foo;
939 }
940
941 if((need%s2ccipher_size)!=0){
942 String message="Bad packet length "+need;
943 if(JSch.getLogger().isEnabled(Logger.FATAL)){
944 JSch.getLogger().log(Logger.FATAL, message);
945 }
946 start_discard(buf, s2ccipher, s2cmac, j, PACKET_MAX_SIZE-s2ccipher_size);
947 }
948
949 if(need>0){
950 io.getByte(buf.buffer, buf.index, need); buf.index+=(need);
951 if(s2ccipher!=null){
952 s2ccipher.update(buf.buffer, s2ccipher_size, need, buf.buffer, s2ccipher_size);
953 }
954 }
955
956 if(s2cmac!=null){
957 s2cmac.update(seqi);
958 s2cmac.update(buf.buffer, 0, buf.index);
959
960 s2cmac.doFinal(s2cmac_result1, 0);
961 io.getByte(s2cmac_result2, 0, s2cmac_result2.length);
962 if(!java.util.Arrays.equals(s2cmac_result1, s2cmac_result2)){
963 if(need > PACKET_MAX_SIZE){
964 throw new IOException("MAC Error");
965 }
966 start_discard(buf, s2ccipher, s2cmac, j, PACKET_MAX_SIZE-need);
967 continue;
968 }
969 }
970
971 seqi++;

Callers 2

connectMethod · 0.95
runMethod · 0.95

Calls 15

start_discardMethod · 0.95
getLoggerMethod · 0.95
byte2strMethod · 0.95
getChannelMethod · 0.95
addRemoteWindowSizeMethod · 0.95
initDeflaterMethod · 0.95
initInflaterMethod · 0.95
getCommandMethod · 0.80
rewindMethod · 0.80
getShortMethod · 0.80
getUIntMethod · 0.80
resetMethod · 0.65

Tested by

no test coverage detected