-
Notifications
You must be signed in to change notification settings - Fork 52
Add fuzzing for wta #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PankajBhojwani
wants to merge
14
commits into
main
Choose a base branch
from
pabhojwa/intelligent/wta_fuzzing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9480dd6
wta fuzzer
PankajBhojwani 2de7ac4
Merge branch 'dev/vanzue/agent' into pabhojwa/intelligent/wta_fuzzing
PankajBhojwani f7f5e0b
issue from merge
PankajBhojwani 5b981bd
Merge remote-tracking branch 'intelligent-ms/main' into pabhojwa/inte…
PankajBhojwani 3af1c00
address comments
PankajBhojwani 2be2289
better cmdline quoting
PankajBhojwani 96de52e
use wta::
PankajBhojwani 60c5d6f
fixes based on review and running fuzzer again
PankajBhojwani 14760ed
better comment
PankajBhojwani 98d20b3
new comments
PankajBhojwani fe2d86f
rustup spell
PankajBhojwani 663144d
ffi and usize as well
PankajBhojwani 339493d
the joys of cmdline parsing, also commit the fuzz cargo.lock file
PankajBhojwani 52e2641
hopefully done now
PankajBhojwani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,20 +33,61 @@ | |
| buildEverything: true | ||
| keepAllExpensiveBuildOutputs: false | ||
|
|
||
| - stage: BuildWtaFuzzer | ||
| displayName: WTA Rust Fuzzer Build | ||
| dependsOn: [] | ||
| condition: succeeded() | ||
| jobs: | ||
| - job: BuildRustFuzzer | ||
| pool: | ||
| ${{ if eq(variables['System.CollectionId'], 'cb55739e-4afe-46a3-970f-1b49d8ee7564') }}: | ||
| name: SHINE-INT-L | ||
| ${{ else }}: | ||
| name: SHINE-OSS-L | ||
| steps: | ||
| - checkout: self | ||
| - bash: | | ||
| set -ex | ||
| msrustup toolchain install ms-nightly | ||
Check failureCode scanning / check-spelling Unrecognized Spelling Error
msrustup is not a recognized word
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| cargo +ms-nightly install cargo-fuzz --locked | ||
| displayName: Install Rust nightly + cargo-fuzz | ||
| - bash: | | ||
| set -ex | ||
| cd tools/wta | ||
| cargo +ms-nightly fuzz build cmdline_builder \ | ||
| --config .cargo/intelligent_terminal_feed.toml | ||
|
PankajBhojwani marked this conversation as resolved.
Outdated
|
||
| displayName: Build WTA fuzz targets | ||
| - bash: | | ||
| set -ex | ||
| # cargo-fuzz outputs to tools/wta/fuzz/target/<triple>/release/ | ||
| cp tools/wta/fuzz/target/x86_64-pc-windows-msvc/release/cmdline_builder.exe \ | ||
| $(Build.ArtifactStagingDirectory)/WtaCmdlineFuzzer.exe | ||
|
PankajBhojwani marked this conversation as resolved.
Outdated
|
||
| displayName: Stage fuzzer artifact | ||
| - task: PublishPipelineArtifact@1 | ||
| displayName: Publish WTA fuzzer | ||
| inputs: | ||
| targetPath: $(Build.ArtifactStagingDirectory)/WtaCmdlineFuzzer.exe | ||
| artifactName: wta-fuzzer | ||
|
|
||
| - stage: Submit | ||
| displayName: Submit to OneFuzz | ||
| dependsOn: [Build] | ||
| dependsOn: [Build, BuildWtaFuzzer] | ||
| condition: succeeded() | ||
| jobs: | ||
| - job: | ||
| pool: | ||
| vmImage: 'ubuntu-latest' | ||
| steps: | ||
| - task: DownloadPipelineArtifact@2 | ||
| displayName: Download artifacts | ||
| displayName: Download C++ fuzzer artifacts | ||
| inputs: | ||
| artifactName: build-x64-Fuzzing | ||
| downloadPath: $(Build.ArtifactStagingDirectory) | ||
| - task: DownloadPipelineArtifact@2 | ||
| displayName: Download WTA fuzzer artifact | ||
| inputs: | ||
| artifactName: wta-fuzzer | ||
| downloadPath: $(Build.ArtifactStagingDirectory) | ||
| - task: UsePythonVersion@0 | ||
| inputs: | ||
| versionSpec: '3.x' | ||
|
|
@@ -77,3 +118,9 @@ | |
| env: | ||
| target_exe_path: $(Build.ArtifactStagingDirectory)/ProtocolFuzzer.exe | ||
| test_name: ProtocolServerParsing | ||
| - bash: | | ||
| onefuzz template libfuzzer basic --colocate_all_tasks --vm_count 1 --target_exe $target_exe_path --notification_config @./build/Fuzz/notifications-ado.json OpenConsole $test_name $(Build.SourceVersion) default | ||
| displayName: Submit OneFuzz Job — WtaCmdlineFuzzer | ||
| env: | ||
| target_exe_path: $(Build.ArtifactStagingDirectory)/WtaCmdlineFuzzer.exe | ||
| test_name: WtaCmdlineBuilder | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [package] | ||
|
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| name = "wta-fuzz" | ||
| version = "0.0.0" | ||
| publish = false | ||
| edition = "2021" | ||
|
|
||
| [package.metadata] | ||
| cargo-fuzz = true | ||
|
|
||
| [dependencies] | ||
| libfuzzer-sys = "0.4" | ||
| arbitrary = { version = "1", features = ["derive"] } | ||
|
|
||
| [dependencies.wta] | ||
| path = ".." | ||
|
|
||
| # Prevent this from interfering with workspaces | ||
| [workspace] | ||
| members = ["."] | ||
|
|
||
| [[bin]] | ||
| name = "cmdline_builder" | ||
| path = "fuzz_targets/cmdline_builder.rs" | ||
| doc = false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
|
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| // Licensed under the MIT license. | ||
| // | ||
| // Fuzz target for WTA's commandline builder. | ||
| // | ||
| // This exercises build_wt_commandline with arbitrary (command, args) pairs | ||
| // generated by the Arbitrary trait, looking for panics and correctness | ||
| // violations in the quoting/escaping logic. | ||
|
|
||
| #![no_main] | ||
|
|
||
| use arbitrary::Arbitrary; | ||
| use libfuzzer_sys::fuzz_target; | ||
| use wta::build_wt_commandline; | ||
|
|
||
| /// Structured fuzz input: a command string and a list of arguments. | ||
| #[derive(Arbitrary, Debug)] | ||
| struct FuzzInput { | ||
| command: String, | ||
| args: Vec<String>, | ||
| } | ||
|
|
||
| fuzz_target!(|input: FuzzInput| { | ||
| // Skip degenerate inputs that would make the test noisy | ||
| if input.command.is_empty() { | ||
| return; | ||
| } | ||
| if input.args.len() > 64 { | ||
| return; | ||
| } | ||
|
|
||
| let result = build_wt_commandline(&input.command, &input.args); | ||
|
|
||
| // Basic sanity checks — these catch escaping failures: | ||
|
|
||
| // 1. The result must start with the command | ||
| assert!( | ||
| result.starts_with(&input.command), | ||
| "Commandline doesn't start with command: {:?} -> {:?}", | ||
| input.command, | ||
| result | ||
| ); | ||
|
PankajBhojwani marked this conversation as resolved.
Outdated
|
||
|
|
||
| // 2. The result must not be empty if the command is non-empty | ||
| assert!(!result.is_empty()); | ||
|
|
||
| // 3. No null bytes should appear (would truncate the commandline) | ||
| if !input.command.contains('\0') && !input.args.iter().any(|a| a.contains('\0')) { | ||
| assert!( | ||
| !result.contains('\0'), | ||
| "Null byte injected into commandline: {:?}", | ||
| result | ||
| ); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
|
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| // Licensed under the MIT license. | ||
| // | ||
| // Library target for WTA — exposes functions needed by fuzz targets | ||
| // and tests without pulling in the full binary's module tree. | ||
| // | ||
| // Only the pure-logic functions are re-exported here. Modules with | ||
| // runtime dependencies (wt_channel, app, protocol) stay in main.rs. | ||
|
|
||
| mod shell_fuzz; | ||
|
|
||
| pub use shell_fuzz::build_wt_commandline; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
|
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| // Licensed under the MIT license. | ||
| // | ||
| // Pure functions extracted from shell_manager for fuzzing. | ||
| // This module is compiled into the library target only and has | ||
| // no dependencies on the binary-specific module tree. | ||
|
PankajBhojwani marked this conversation as resolved.
Outdated
|
||
|
|
||
| /// Build a commandline string from a command and its arguments for WT pane | ||
| /// creation. This is the string passed to `create_tab`'s `commandline` param. | ||
| /// | ||
| /// # Security note | ||
| /// | ||
| /// This function is a fuzz target — the quoting must be robust against | ||
| /// agent-supplied strings containing shell metacharacters. | ||
|
PankajBhojwani marked this conversation as resolved.
Outdated
|
||
| pub fn build_wt_commandline(command: &str, args: &[String]) -> String { | ||
| let mut cmdline = command.to_string(); | ||
| for arg in args { | ||
| cmdline.push(' '); | ||
| // Quote args containing spaces or double quotes | ||
| if arg.contains(' ') || arg.contains('"') { | ||
| cmdline.push('"'); | ||
| // Escape embedded double quotes by doubling them | ||
| for ch in arg.chars() { | ||
| if ch == '"' { | ||
| cmdline.push('"'); | ||
| } | ||
| cmdline.push(ch); | ||
| } | ||
| cmdline.push('"'); | ||
| } else { | ||
| cmdline.push_str(arg); | ||
| } | ||
| } | ||
|
PankajBhojwani marked this conversation as resolved.
Outdated
|
||
| cmdline | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.