Skip to content
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

vscode: add fuzz introspector installation and usage #12887

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions tools/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@
"command": "oss-fuzz.testFuzzerCFLite",
"title": "OSS-Fuzz: [CFLite] Test running a specific fuzzer.",
"description": "Builds the CFLite setup and runs a fuzzer for a short period of time."
},
{
"command": "oss-fuzz.setupFuzzIntrospector",
"title": "OSS-Fuzz: Set up Fuzz Introspector",
"description": "Install fuzz introspector on the system"
},
{
"command": "oss-fuzz.runFuzzIntrospector",
"title": "OSS-Fuzz: Run Full Fuzz Introspector",
"description": "Runs a full Fuzz Introspector"
}
],
"walkthroughs":[
Expand Down
58 changes: 58 additions & 0 deletions tools/vscode-extension/src/commands/cmdRunFI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

import * as vscode from 'vscode';
// import path = require('path');
import {println} from '../logger';
import {extensionConfig} from '../config';
import {isPathValidOssFuzzPath} from '../ossfuzzWrappers';
import {systemSync} from '../utils';

/**
* Function for setting up Fuzz Introspector by way of a Python virtual env.
*/
export async function runFuzzIntrospectorHandler() {
println('Setting up oss-fuzz in /tmp/');

const workspaceFolder = vscode.workspace.workspaceFolders;
if (!workspaceFolder) {
return;
}
const pathOfLocal = workspaceFolder[0].uri.fsPath;
println('path of local: ' + pathOfLocal);

// First check if we already have Fuzz Introspector installed.
const tmpOssFuzzRepositoryPath = '/tmp/fi-tmp-env';

if ((await isPathValidOssFuzzPath(tmpOssFuzzRepositoryPath)) === true) {
println('Fuzz Introspector virtual env already exists in /tmp/fi-tmp-env');
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
return;
}

const cmdToExec = '/tmp/fi-tmp-env/bin/fuzz-introspector';
const args: Array<string> = [
'full',
'--target_dir=${pathOfLocal}',
'--language=c',
];
const [res, output] = await systemSync(cmdToExec, args);
if (res === false) {
println('Failed run FI');
println(output);
return;
}
}
59 changes: 59 additions & 0 deletions tools/vscode-extension/src/commands/cmdSetupFI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

import {println} from '../logger';
import {extensionConfig} from '../config';
import {isPathValidOssFuzzPath} from '../ossfuzzWrappers';
import {systemSync} from '../utils';

/**
* Function for setting up Fuzz Introspector by way of a Python virtual env.
*/
export async function setUpFuzzIntrospectorHandler() {
println('Setting up oss-fuzz in /tmp/');

// First check if we already have Fuzz Introspector installed.
const tmpOssFuzzRepositoryPath = '/tmp/fi-tmp-env';

if ((await isPathValidOssFuzzPath(tmpOssFuzzRepositoryPath)) === true) {
println('Fuzz Introspector virtual env already exists in /tmp/fi-tmp-env');
extensionConfig.ossFuzzPepositoryWorkPath = tmpOssFuzzRepositoryPath;
return;
}

const cmdToExec = 'python3.11';
const args: Array<string> = ['-m', 'virtualenv', tmpOssFuzzRepositoryPath];
const [res, output] = await systemSync(cmdToExec, args);
if (res === false) {
println('Failed to create virtual environment');
println(output);
return;
}

const cmdToExec2 = '/tmp/fi-tmp-env/bin/python3.11';
const args2: Array<string> = [
'-m',
'pip',
'install',
'fuzz-introspector==0.1.4',
];
const [res2, output2] = await systemSync(cmdToExec2, args2);
if (res2 === false) {
println('Failed to create virtual environment');
println(output2);
return;
}
}
22 changes: 22 additions & 0 deletions tools/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {runEndToEndAndGetCoverage} from './commands/cmdEndToEndCoverage';
import {listFuzzersHandler} from './commands/cmdListFuzzers';
import {cmdInputCollectorReproduceTestcase} from './commands/cmdReproduceTestcase';
import {cmdDispatcherTemplate} from './commands/cmdTemplate';
import {setUpFuzzIntrospectorHandler} from './commands/cmdSetupFI';
import {runFuzzIntrospectorHandler} from './commands/cmdRunFI';
import {cmdDispatcherGenerateClusterfuzzLite} from './commands/cmdDispatcherGenerateClusterfuzzLite';
import {setUpOssFuzzHandler} from './commands/cmdSetupOSSFuzz';
import {setOssFuzzPath} from './commands/cmdSetOSSFuzzPath';
Expand Down Expand Up @@ -189,6 +191,26 @@ export function activate(context: vscode.ExtensionContext) {
println('CMD end: testFuzzerCFLite');
})
);

context.subscriptions.push(
vscode.commands.registerCommand(
'oss-fuzz.setupFuzzIntrospector',
async () => {
println('CMD start: setup FI');
await setUpFuzzIntrospectorHandler();
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'oss-fuzz.runFuzzIntrospector',
async () => {
println('CMD start: run Fuzz Introspector');
await runFuzzIntrospectorHandler();
}
)
);
}

// This method is called when your extension is deactivated
Expand Down
Loading