Revert "FFI: don't overwrite input length on ossuary_recv_data"
This reverts commit cb57fdbe3e402a475fe0db5daf581bffafd80bdd.
Forgot that this was for non-blocking... it was just buggy.
Whoops.
// Client receives decrypted data
out_len = sizeof(client_buf);
- bytes = ossuary_recv_data(client_conn, client_buf, bytes, client_buf, &out_len);
+ bytes = ossuary_recv_data(client_conn, client_buf, &bytes, client_buf, &out_len);
printf("client recv data bytes: %d\n", bytes);
printf("decrypted: %s\n", client_buf);
uint8_t *in_buf, uint16_t in_buf_len,
uint8_t *out_buf, uint16_t *out_buf_len);
int32_t ossuary_recv_data(OssuaryConnection *conn,
- uint8_t *in_buf, uint16_t in_buf_len,
+ uint8_t *in_buf, uint16_t *in_buf_len,
uint8_t *out_buf, uint16_t *out_buf_len);
#define _OSSUARY_H
#[no_mangle]
pub extern "C" fn ossuary_recv_data(conn: *mut OssuaryConnection,
- in_buf: *mut u8, in_buf_len: u16,
+ in_buf: *mut u8, in_buf_len: *mut u16,
out_buf: *mut u8, out_buf_len: *mut u16) -> i32 {
- if conn.is_null() || in_buf.is_null() || out_buf.is_null() || out_buf_len.is_null() {
+ if conn.is_null() || in_buf.is_null() || out_buf.is_null() ||
+ in_buf_len.is_null() || out_buf_len.is_null() {
return -1i32;
}
let conn = unsafe { &mut *conn };
let r_out_buf: &mut [u8] = unsafe {
std::slice::from_raw_parts_mut(out_buf, *out_buf_len as usize)
};
- let r_in_buf: &[u8] = unsafe { std::slice::from_raw_parts(in_buf, in_buf_len as usize) };
+ let r_in_buf: &[u8] = unsafe { std::slice::from_raw_parts(in_buf, *in_buf_len as usize) };
let mut out_slice = r_out_buf;
let mut in_slice = r_in_buf;
let bytes_read = match conn.recv_data(&mut in_slice, &mut out_slice) {
Ok((read,written)) => {
unsafe {
+ *in_buf_len = read as u16;
*out_buf_len = written as u16;
};
read as i32
let in_buf = reader.fill_buf().unwrap();
if in_buf.len() > 0 {
let mut out_len = out_buf.len() as u16;
- let in_len = in_buf.len() as u16;
+ let mut in_len = in_buf.len() as u16;
let len = ossuary_recv_data(
conn,
- (in_buf) as *const [u8] as *mut u8, in_len,
+ (in_buf) as *const [u8] as *mut u8, &mut in_len,
(&out_buf) as *const u8 as *mut u8, &mut out_len);
if len != -1 {
println!("CLIB READ: {:?}",
break;
}
let mut out_len = out_buf.len() as u16;
- let in_len = in_buf.len() as u16;
+ let mut in_len = in_buf.len() as u16;
let len = ossuary_recv_data(
conn,
- in_buf as *const [u8] as *mut u8, in_len,
+ in_buf as *const [u8] as *mut u8, &mut in_len,
(&out_buf) as *const u8 as *mut u8, &mut out_len);
if len == -1 {
break;