Erasing arguments with Vec<u8>.

This commit is contained in:
sergiotarxz 2020-11-06 23:04:21 +01:00
parent 91e112d825
commit 8dc05f5346
1 changed files with 16 additions and 5 deletions

View File

@ -5,6 +5,7 @@ use crate::constants::SSH_FXP_INIT;
use crate::constants::SSH_FXP_VERSION;
use std::io::{BufReader, BufWriter, Read, Write};
use std::process::exit;
pub fn dispatch_packet(packet: Packet) {
let mut buff_stdout = BufWriter::new(std::io::stdout());
@ -31,7 +32,9 @@ pub fn dispatch_packet(packet: Packet) {
};
let serialized_response = response_packet.serialize();
eprintln!("{:#?}", &serialized_response);
buff_stdout.write(&serialized_response).expect("Unable to write to stdout.");
buff_stdout
.write(&serialized_response)
.expect("Unable to write to stdout.");
buff_stdout.flush().expect("Unable to flush stdout.");
}
}
@ -56,18 +59,26 @@ impl Packet {
packet_header.length, packet_header.type_packet
);
let mut data: Vec<u8> = Vec::new();
data.resize(packet_header.length as usize - 1, 0);
if packet_header.length == 0 {
exit(0);
}
if packet_header.length as usize - 1 > 34000 {
panic!(
"This packet is bigger than supported {}, refusing to allocate memory to handle that.", packet_header.length
);
}
data.resize(packet_header.length as usize - 1, 10);
match buff_stdin.read(&mut data) {
Ok(ok) => ok,
Err(err) => panic!("Could not fetch data: {}", err),
};
eprintln!("{:#?}", data);
Packet::deserialize(packet_header, data)
Packet::deserialize(packet_header, &data)
}
pub fn deserialize(packet_header: header::PacketHeader, data: Vec<u8>) -> Packet {
pub fn deserialize(packet_header: header::PacketHeader, data: &[u8]) -> Packet {
Packet {
packet_header: packet_header,
data: data,
data: data.to_vec(),
}
}
pub fn serialize(&mut self) -> Vec<u8> {