-
Notifications
You must be signed in to change notification settings - Fork 273
Input string printable TG-808 #1513
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
peterschrammel
merged 10 commits into
diffblue:develop
from
romainbrenguier:feature/input-string-printable
Nov 3, 2017
+170
−21
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e1280cc
Add utility function add_constraint_on_characters
romainbrenguier cb01526
Minor refactoring in add_default_axioms
romainbrenguier 1d92c48
Add string primitive to constrain characters
romainbrenguier 514e6a1
Add function to call constrain_character primitive
romainbrenguier ae5f32e
Add a printable option to string initialization
romainbrenguier 8e92362
Propagate string-printable option in object_factory
romainbrenguier e65e340
Use command line option for string-printable param
romainbrenguier 542a26d
Stop adding printable constraints on all strings
romainbrenguier b0de0e3
Test for string printable option on input strings
romainbrenguier d2c3752
Remove string_printable option from the solver
romainbrenguier 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
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
regression/strings-smoke-tests/java_string_printable/Test.java
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,21 @@ | ||
public class Test { | ||
|
||
public static String check(String t) { | ||
String s = t.concat("$£¥\u0000\u0008\u0010\u001F"); | ||
// This should be disallowed because "\u0000" is not printable | ||
assert(!s.equals("\u0000$£¥\u0000\u0008\u0010\u001F")); | ||
// This can fail when t="a" which is printable | ||
assert(!s.equals("a$£¥\u0000\u0008\u0010\u001F")); | ||
return s; | ||
} | ||
|
||
public static boolean check_char(String s, char c) { | ||
if(s == null) | ||
return false; | ||
// This should be -1 for all non-printable character | ||
int i = s.indexOf(c); | ||
boolean b = (i == -1 || (c >= ' ' && c <= '~')); | ||
assert(b); | ||
return b; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
regression/strings-smoke-tests/java_string_printable/test.desc
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,8 @@ | ||
CORE | ||
Test.class | ||
--refine-strings --function Test.check --string-max-length 100 --string-printable --java-assume-inputs-non-null | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
assertion.* file Test.java line 6 .* SUCCESS | ||
assertion.* file Test.java line 8 .* FAILURE | ||
-- |
7 changes: 7 additions & 0 deletions
7
regression/strings-smoke-tests/java_string_printable/test_char.desc
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,7 @@ | ||
CORE | ||
Test.class | ||
--refine-strings --function Test.check_char --string-max-length 100 --string-printable | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
assertion.* file Test.java line 18 .* SUCCESS | ||
-- |
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
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
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.
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.
Do we check this when accepting the command-line option? If not we should; it's always better to fail early on bad user input so they don't have to wait until symex completes to learn they've done it wrong
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.
For now, this doesn't come directly from the command-line, when
--string-printable
is setjava_object_factory
will call this primitive with the fixed input " -~" so there is no risk of bad user input.In the future, we could allow the user to configure that and have more complex char_set (as you have in regex for instance), but this is outside the scope of this PR.
Because this cannot really be set by the user, this would require some unit test. Alternatively I could add a test with something like this:
f(String s, char c){assert(s.find(c)=-1 || (c>= ' ' && c<= '~'));}
which ensures we cannot find a non ascii-printable character in a string.