Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions aw-server/src/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ pub mod android {
pub unsafe extern "C" fn Java_net_activitywatch_android_RustInterface_startServer(
env: JNIEnv,
_: JClass,
java_host: JString,
) {
info!("Starting server...");
start_server();
let host = jstring_to_string(&env, java_host);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the Android app passes an invalid or malformed IP address, config.address.parse().unwrap() at config.rs:69 will panic

Suggested change
let host = jstring_to_string(&env, java_host);
let host = match jstring_to_string(&env, java_host) {
Ok(h) => h,
Err(e) => {
error!("Invalid host string: {}", e);
return;
}
};

info!("Starting server on {}...", host);
start_server(host);
info!("Server exited");
}

#[rocket::main]
async fn start_server() {
async fn start_server(host: String) {
info!("Building server state...");

// FIXME: Why is unsafe needed here? Can we get rid of it?
Expand All @@ -122,6 +124,7 @@ pub mod android {
info!("Using server_state:: device_id: {}", server_state.device_id);

let mut server_config: AWConfig = AWConfig::default();
server_config.address = host;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if an invalid IP address is passed from Android, to_rocket_config() will panic at the .parse().unwrap() call in config.rs:69. validate the host string or handle the parse error gracefully

server_config.port = 5600;

endpoints::build_rocket(server_state, server_config)
Expand Down
Loading