Skip to content

Commit 2685cb6

Browse files
authored
Fix local fuzzing mode (microsoft#2669)
* repairing local fuzzing mode * make clippy happy * make the ui an option
1 parent 7091c54 commit 2685cb6

File tree

12 files changed

+49
-37
lines changed

12 files changed

+49
-37
lines changed

src/agent/onefuzz-task/src/local/cmd.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::local::{
1010
};
1111
use anyhow::{Context, Result};
1212
use clap::{App, Arg, SubCommand};
13-
use crossterm::tty::IsTty;
1413
use std::str::FromStr;
1514
use std::time::Duration;
1615
use strum::IntoEnumIterator;
@@ -36,9 +35,11 @@ enum Commands {
3635
}
3736

3837
const TIMEOUT: &str = "timeout";
38+
const TUI: &str = "tui";
3939

4040
pub async fn run(args: clap::ArgMatches<'static>) -> Result<()> {
4141
let running_duration = value_t!(args, TIMEOUT, u64).ok();
42+
let start_ui = args.is_present(TUI);
4243

4344
let (cmd, sub_args) = args.subcommand();
4445
let command =
@@ -48,7 +49,7 @@ pub async fn run(args: clap::ArgMatches<'static>) -> Result<()> {
4849
.ok_or_else(|| anyhow!("missing subcommand arguments"))?
4950
.to_owned();
5051

51-
let terminal = if std::io::stdout().is_tty() {
52+
let terminal = if start_ui {
5253
Some(TerminalUi::init()?)
5354
} else {
5455
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
@@ -111,6 +112,12 @@ pub fn args(name: &str) -> App<'static, 'static> {
111112
.long(TIMEOUT)
112113
.help("The maximum running time in seconds")
113114
.takes_value(true),
115+
)
116+
.arg(
117+
Arg::with_name(TUI)
118+
.long(TUI)
119+
.help("Enable the terminal UI")
120+
.takes_value(false),
114121
);
115122

116123
for subcommand in Commands::iter() {

src/agent/onefuzz-task/src/local/common.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ pub async fn build_local_context(
251251
task_id,
252252
instance_id,
253253
setup_dir,
254-
machine_identity: MachineIdentity::from_metadata().await?,
254+
machine_identity: MachineIdentity {
255+
machine_id: Uuid::nil(),
256+
machine_name: "local".to_string(),
257+
scaleset_name: None,
258+
},
255259
instance_telemetry_key: None,
256260
heartbeat_queue: None,
257261
microsoft_telemetry_key: None,

src/agent/onefuzz-task/src/local/coverage.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn build_coverage_config(
2828
) -> Result<Config> {
2929
let target_exe = get_cmd_exe(CmdType::Target, args)?.into();
3030
let target_env = get_cmd_env(CmdType::Target, args)?;
31-
let target_options = get_cmd_arg(CmdType::Target, args);
31+
let mut target_options = get_cmd_arg(CmdType::Target, args);
3232
let target_timeout = value_t!(args, TARGET_TIMEOUT, u64).ok();
3333
let coverage_filter = value_t!(args, TARGET_TIMEOUT, String).ok();
3434

@@ -47,6 +47,10 @@ pub fn build_coverage_config(
4747
let coverage = get_synced_dir(COVERAGE_DIR, common.job_id, common.task_id, args)?
4848
.monitor_count(&event_sender)?;
4949

50+
if target_options.is_empty() {
51+
target_options.push("{input}".to_string());
52+
}
53+
5054
let config = Config {
5155
target_exe,
5256
target_env,

src/agent/onefuzz-task/src/tasks/analysis/generic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ async fn poll_inputs(
157157
heartbeat.alive();
158158
if let Some(message) = input_queue.pop().await? {
159159
let input_url = message
160-
.parse(|data| BlobUrl::parse(str::from_utf8(data)?))
160+
.get::<reqwest::Url>()
161+
.and_then(BlobUrl::parse)
161162
.with_context(|| format!("unable to parse URL from queue: {:?}", message))?;
162163
if !already_checked(config, &input_url).await? {
163164
let destination_path = _copy(input_url, &tmp_dir).await?;

src/agent/onefuzz-task/src/tasks/generic/input_poller/callback.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ where
9797
P: Processor + Send,
9898
{
9999
fn parse(&mut self, msg: &Message) -> Result<Url> {
100-
let url = msg.parse(|data| {
101-
let data = std::str::from_utf8(data)?;
102-
Ok(Url::parse(data)?)
103-
})?;
100+
let url = msg.get()?;
104101
Ok(url)
105102
}
106103
}

src/agent/onefuzz-task/src/tasks/merge/generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub async fn spawn(config: Arc<Config>) -> Result<()> {
5555
config.unique_inputs.sync_pull().await?;
5656
let queue = QueueClient::new(config.input_queue.clone())?;
5757
if let Some(msg) = queue.pop().await? {
58-
let input_url = msg.parse(utils::parse_url_data);
58+
let input_url = msg.get();
5959
let input_url = match input_url {
6060
Ok(url) => url,
6161
Err(err) => {

src/agent/onefuzz-task/src/tasks/merge/libfuzzer_merge.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ async fn process_message(config: Arc<Config>, input_queue: QueueClient) -> Resul
8585
utils::reset_tmp_dir(tmp_dir).await?;
8686

8787
if let Some(msg) = input_queue.pop().await? {
88-
let input_url = msg.parse(|data| {
89-
let data = std::str::from_utf8(data)?;
90-
Ok(Url::parse(data)?)
91-
});
88+
let input_url = msg.get();
9289
let input_url: Url = match input_url {
9390
Ok(url) => url,
9491
Err(err) => {

src/agent/onefuzz-task/src/tasks/utils.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ pub async fn reset_tmp_dir(tmp_dir: impl AsRef<Path>) -> Result<()> {
6262
Ok(())
6363
}
6464

65-
pub fn parse_url_data(data: &[u8]) -> Result<Url> {
66-
let text = std::str::from_utf8(data)?;
67-
let url = Url::parse(text)?;
68-
69-
Ok(url)
70-
}
71-
7265
#[async_trait]
7366
pub trait CheckNotify {
7467
async fn is_notified(&self, delay: Duration) -> bool;

src/agent/onefuzz/src/sanitizer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
use std::collections::HashMap;
55
use std::path::Path;
66

7-
use anyhow::{bail, Result};
7+
use anyhow::{bail, Context, Result};
88

99
pub fn default_llvm_symbolizer_path() -> Result<String> {
10-
Ok(std::env::var("LLVM_SYMBOLIZER_PATH")?)
10+
std::env::var("LLVM_SYMBOLIZER_PATH")
11+
.context("LLVM_SYMBOLIZER_PATH environment variable is not set")
1112
}
1213

1314
pub fn default_sanitizer_env_vars() -> Result<HashMap<String, String>> {

src/agent/storage-queue/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ serde = { version = "1.0", features = ["derive"]}
2121
serde_derive = "1.0"
2222
serde_json = "1.0"
2323
serde-xml-rs = "0.6"
24+
bincode = "1.3"
2425
tokio = { version = "1.16" , features=["full"] }
2526
queue-file = "1.4"
2627
uuid = { version = "0.8", features = ["serde", "v4"] }

0 commit comments

Comments
 (0)