This is an archive of the discontinued LLVM Phabricator instance.

Bounds check argument_with_type_tag attribute.
ClosedPublic

Authored by mattd on Nov 28 2017, 12:44 PM.

Details

Summary

Fixes: PR28520

Perform a bounds check on a function's argument list, before accessing any index value specified by an 'argument_with_type_tag' attribute.

Diff Detail

Event Timeline

mattd created this revision.Nov 28 2017, 12:44 PM
aaron.ballman added inline comments.Nov 29 2017, 8:30 AM
include/clang/Basic/DiagnosticSemaKinds.td
7922–7925

These should be combined into a single diagnostic: %select{type|argument}0 tag index %1 is greater than the number of arguments specified

include/clang/Sema/Sema.h
10458–10459

const Expr * (space before the *). Same below in the definition.

lib/Sema/SemaChecking.cpp
12345

Spurious newline?

12365

Spurious newline?

test/Sema/error-type-safety.cpp
4–5

Is this declaration necessary?

17

Can you also add a test for a boundary case so we can be sure there are no off-by-one errors introduced later?

mattd updated this revision to Diff 124783.Nov 29 2017, 11:06 AM
  • Removed the new lines.
  • Added white space between the data type and pointer character.
  • Updated the test to check the exact bounds, and over-bounds cases
  • Combined the diagnostic messages into one via 'select'
mattd marked 6 inline comments as done.Nov 29 2017, 11:26 AM
mattd added inline comments.
test/Sema/error-type-safety.cpp
4–5

Hi Aaron, thanks for the input. Yes, defining the tag is necessary in order to test the argument index. If the type tag is not satisfied, the code path checking argument tag index will never be reached. My update will test the bounds and is a little more comprehensive.

aaron.ballman accepted this revision.Nov 29 2017, 1:23 PM

Thanks, LGTM!

This revision is now accepted and ready to land.Nov 29 2017, 1:23 PM
mattd marked an inline comment as done.Nov 29 2017, 2:12 PM

Thanks for the approval Aaron. I do not have commit access, would you mind submitting this on my behalf?

aaron.ballman closed this revision.Nov 29 2017, 3:11 PM

Thanks for the approval Aaron. I do not have commit access, would you mind submitting this on my behalf?

Happy to do so -- I've commit in r319383, thank you for the patch!