-
Notifications
You must be signed in to change notification settings - Fork 45
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
Basic support for assert() #6529
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,7 @@ template <Section... Sections> class OutputFile { | |
|
||
// The FileHeader is constructed at offset zero of the mapped memory (file). | ||
// It contains the metadata required to parse a TDAG file. Initially each | ||
// section is assumed to be allocation_size in size. On destruction of | ||
// section is assumed to be 0 bytes in size. On destruction of | ||
// the OutputFile instance the size field of each section is updated to | ||
// reflect the actual, used size. | ||
struct FileHeader { | ||
|
@@ -97,7 +97,7 @@ template <Section... Sections> class OutputFile { | |
(SectionMeta{.tag = Sections::tag, | ||
.align = Sections::align_of, | ||
.offset = 0, | ||
.size = Sections::allocation_size})...}; | ||
.size = 0})...}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does setting the size to 0 for a section mean the section technically won't exist when output? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so? I guess this was done to have correct information in the case when we have a section that's optional, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also we should update the comment above this code to reflect this change :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just the initial value. The final value will be set in the destructor of the |
||
}; | ||
|
||
OutputFile(std::filesystem::path const &filename) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <cassert> | ||
#include <unistd.h> | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
char data[2]; | ||
read(0, data, sizeof(data)); | ||
|
||
// This will terminate the program unexpectedly (tdag sizes might not be updated). | ||
assert(data[0] == data[1]); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
import subprocess | ||
import pytest | ||
from polytracker import taint_dag, PolyTrackerTrace | ||
from typing import cast | ||
|
||
|
||
@pytest.mark.program_trace("test_assert.cpp") | ||
def test_assert(instrumented_binary: Path, trace_file: Path): | ||
stdin_data = "ab" | ||
|
||
subprocess.run( | ||
[str(instrumented_binary)], | ||
input=stdin_data.encode("utf-8"), | ||
env={"POLYDB": str(trace_file), "POLYTRACKER_STDIN_SOURCE": str(1)}, | ||
) | ||
program_trace = PolyTrackerTrace.load(trace_file) | ||
assert isinstance(program_trace, taint_dag.TDProgramTrace) | ||
|
||
tdfile = program_trace.tdfile | ||
assert tdfile.label_count == 4 | ||
|
||
t1 = cast(taint_dag.TDSourceNode, tdfile.decode_node(1)) | ||
assert isinstance(t1, taint_dag.TDSourceNode) | ||
|
||
t2 = cast(taint_dag.TDSourceNode, tdfile.decode_node(2)) | ||
assert isinstance(t2, taint_dag.TDSourceNode) | ||
|
||
t3 = cast(taint_dag.TDSourceNode, tdfile.decode_node(3)) | ||
assert isinstance(t3, taint_dag.TDRangeNode) | ||
assert t3.first == 1 | ||
assert t3.last == 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "uninstrumented" result in? Does this mean the function is stubbed and polytracker does not interact with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Source: https://clang.llvm.org/docs/DataFlowSanitizer.html#abi-list
Does this answer your question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I didn't realize this is/was the same as the regular DFSan ABI list, my bad.