Skip to content

Encode string literals as a byte array - #1903

Merged
zhassan-aws merged 3 commits into
model-checking:mainfrom
zhassan-aws:str-encoding
Nov 15, 2022
Merged

zhassan-aws merged 3 commits into
model-checking:mainfrom
zhassan-aws:str-encoding

Conversation

@zhassan-aws

Copy link
Copy Markdown
Contributor

Description of changes:

Kani currently encodes string slices (str) as null-terminated C slices, which is unsound. This PR changes the encoding to a byte array to guarantee that Kani reports pointer accesses outside the slice as invalid dereferences.

Resolved issues:

Resolves #1665

Related RFC:

Optional #ISSUE-NUMBER.

Call-outs:

Testing:

  • How is this change tested? A new test was added, and existing tests were slightly modified

  • Is this a refactor change? No

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@zhassan-aws
zhassan-aws requested a review from a team as a code owner November 15, 2022 19:27

@celinval celinval left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this

ExprValue::AddressOf(address) => match address.value() {
ExprValue::Symbol { identifier } => {
// lookup the string literal in the goto context
let name = self.str_literals.get(identifier).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not for this PR, but I was wondering if we could map directly Expr -> String Literal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be better. I couldn't do that because Expr is not "hash"able. I'll add a comment though.

@zhassan-aws
zhassan-aws merged commit 983c5c1 into model-checking:main Nov 15, 2022
@zhassan-aws
zhassan-aws deleted the str-encoding branch November 15, 2022 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kani encodes string slices as null-terminated C slices

2 participants