Skip to content

Commit

Permalink
session: Handle invalid strings in keyboard prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
yodaldevoid committed Nov 5, 2024
1 parent 38f989c commit 1868c37
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,23 @@ impl Session {

let prompter = unsafe { &mut **(abstrakt as *mut *mut P) };

let username =
unsafe { slice::from_raw_parts(username as *const u8, username_len as usize) };
let username = String::from_utf8_lossy(username);
let username = if !username.is_null() && username_len >= 0 {
let username = unsafe {
slice::from_raw_parts(username as *const u8, username_len as usize)
};
String::from_utf8_lossy(username)
} else {
Cow::Borrowed("")
};

let instruction = unsafe {
slice::from_raw_parts(instruction as *const u8, instruction_len as usize)
let instruction = if !instruction.is_null() && instruction_len >= 0 {
let instruction = unsafe {
slice::from_raw_parts(instruction as *const u8, instruction_len as usize)
};
String::from_utf8_lossy(instruction)
} else {
Cow::Borrowed("")
};
let instruction = String::from_utf8_lossy(instruction);

let prompts = unsafe { slice::from_raw_parts(prompts, num_prompts as usize) };
let responses =
Expand Down

0 comments on commit 1868c37

Please sign in to comment.