-
Notifications
You must be signed in to change notification settings - Fork 33
Handle real segfaults in fuzz targets #602
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a988ca5
Add test for and handling of a real segfault
br-lewis 7fcc9fb
Fix misspelled function
br-lewis e163c58
Clean up package files
br-lewis 4f07701
Fix clean build not building native-signal
br-lewis 7a4a3f3
Merge branch 'main' into FUZZ-774-handle-real-segfaults
br-lewis 467f82e
Hopefully fix the build in CI
br-lewis 69a8f0f
Try moving signal handler assignment to the same thread
br-lewis a2ebfcd
Time to do some CI print debugging
br-lewis 5d965aa
Add log line to setjmp
br-lewis 00f800d
Try add setjmp to CallJsFuzzCallback
br-lewis fd8a5ee
Clean up now that it works in CI
br-lewis 99f5a99
Merge branch 'main' into FUZZ-774-handle-real-segfaults
br-lewis dc149ef
Remove compile_commands from gitignore and ignore it in linting
br-lewis 6d5416a
Run formatter
br-lewis fc14d48
Add copyright header
br-lewis baf9364
Clean up some documentation and packaging files
br-lewis cb3b5f7
Clean up tests a little
br-lewis 71aa6af
Fix formatting
br-lewis 87c6db4
Add formatting for native-signal
br-lewis 2a4c688
Merge branch 'main' into FUZZ-774-handle-real-segfaults
br-lewis 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
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
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
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
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,45 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
cmake_policy(SET CMP0091 NEW) | ||
cmake_policy(SET CMP0042 NEW) | ||
|
||
project(signal_impl) | ||
|
||
set(CMAKE_CXX_STANDARD 17) # mostly supported since GCC 7 | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(LLVM_ENABLE_LLD TRUE) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: | ||
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") | ||
cmake_policy(SET CMP0135 NEW) | ||
endif() | ||
|
||
# To help with development, let's write compile_commands.json unconditionally. | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS 1) | ||
|
||
include_directories(${CMAKE_JS_INC}) | ||
|
||
file(GLOB SOURCE_FILES "*.cpp") | ||
|
||
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") | ||
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB}) | ||
|
||
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) | ||
# Generate node.lib | ||
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) | ||
endif() | ||
|
||
# Enable the functionality of Node-API version 4 and disable everything added | ||
# later, so that we don't accidentally break compatibility with older versions | ||
# of Node (see https://nodejs.org/api/n-api.html#node-api-version-matrix). | ||
# | ||
# Note that prebuild recommends in its README to use ${napi_build_version} here, | ||
# but the variable is only set when cmake-js is invoked via prebuild (in which | ||
# case the API version is taken from "binary.napi_versions" in package.json). | ||
# Since we want the build to work in other cases as well, let's just use a | ||
# constant. (There is currently no point in a dynamic setting anyway since we | ||
# specify the oldest version that we're compatible with, and Node-API's ABI | ||
# stability guarantees that this version is available in all future Node-API | ||
# releases.) | ||
add_definitions(-DNAPI_VERSION=4) |
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,27 @@ | ||
/* | ||
* Copyright 2023 Code Intelligence GmbH | ||
* | ||
* 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 { default as bind } from "bindings"; | ||
|
||
type NativeAddon = { | ||
sigsegv: (loc: number) => void; | ||
}; | ||
|
||
const addon: NativeAddon = bind("signal_impl"); | ||
|
||
export function sigsegv(loc: number) { | ||
addon.sigsegv(loc); | ||
} |
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 @@ | ||
{ | ||
"name": "native-signal", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"install": "npm run build", | ||
bertschneider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"build": "cmake-js build && tsc" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
bertschneider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"devDependencies": { | ||
"typescript": "^5.2.2" | ||
}, | ||
"binary": { | ||
"napi_versions": [ | ||
4 | ||
] | ||
}, | ||
"dependencies": { | ||
"bindings": "^1.5.0", | ||
"cmake-js": "^7.2.1" | ||
} | ||
} |
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,25 @@ | ||
#include <iostream> | ||
bertschneider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include <signal.h> | ||
|
||
#include <napi.h> | ||
|
||
void sigsegv(const Napi::CallbackInfo &info) | ||
bertschneider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (info.Length() != 1 || !info[0].IsNumber()) | ||
{ | ||
throw Napi::Error::New(info.Env(), "Need a single integer argument"); | ||
} | ||
// accepts a parameter to prevent the compiler from optimizing a static segfault away | ||
int location = info[0].ToNumber(); | ||
int *a = (int *)location; | ||
*a = 10; | ||
} | ||
|
||
Napi::Object Init(Napi::Env env, Napi::Object exports) | ||
{ | ||
exports["sigsegv"] = Napi::Function::New<sigsegv>(env); | ||
|
||
return exports; | ||
} | ||
|
||
NODE_API_MODULE(signal_impl, Init); |
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.