Erasing arguments with Vec<u8>.
This commit is contained in:
parent
91e112d825
commit
8dc05f5346
@ -5,6 +5,7 @@ use crate::constants::SSH_FXP_INIT;
|
|||||||
use crate::constants::SSH_FXP_VERSION;
|
use crate::constants::SSH_FXP_VERSION;
|
||||||
|
|
||||||
use std::io::{BufReader, BufWriter, Read, Write};
|
use std::io::{BufReader, BufWriter, Read, Write};
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
pub fn dispatch_packet(packet: Packet) {
|
pub fn dispatch_packet(packet: Packet) {
|
||||||
let mut buff_stdout = BufWriter::new(std::io::stdout());
|
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();
|
let serialized_response = response_packet.serialize();
|
||||||
eprintln!("{:#?}", &serialized_response);
|
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.");
|
buff_stdout.flush().expect("Unable to flush stdout.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,18 +59,26 @@ impl Packet {
|
|||||||
packet_header.length, packet_header.type_packet
|
packet_header.length, packet_header.type_packet
|
||||||
);
|
);
|
||||||
let mut data: Vec<u8> = Vec::new();
|
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) {
|
match buff_stdin.read(&mut data) {
|
||||||
Ok(ok) => ok,
|
Ok(ok) => ok,
|
||||||
Err(err) => panic!("Could not fetch data: {}", err),
|
Err(err) => panic!("Could not fetch data: {}", err),
|
||||||
};
|
};
|
||||||
eprintln!("{:#?}", data);
|
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 {
|
||||||
packet_header: packet_header,
|
packet_header: packet_header,
|
||||||
data: data,
|
data: data.to_vec(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn serialize(&mut self) -> Vec<u8> {
|
pub fn serialize(&mut self) -> Vec<u8> {
|
||||||
|
Loading…
Reference in New Issue
Block a user