-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: Taint propagation through dynamic_cast #2713
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
C++: Taint propagation through dynamic_cast #2713
Conversation
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.
LGTM
@@ -96,6 +96,10 @@ private predicate operandIsPropagated(Operand operand, IntValue bitOffset) { | |||
bitOffset = Ints::mul(convert.getDerivation().getByteOffset(), 8) | |||
) | |||
or | |||
// Conversion using dynamic_cast results in an unknown offset | |||
instr instanceof CheckedConvertOrNullInstruction and | |||
bitOffset = Ints::unknown() |
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.
Must the offset be unknown
in order for the alias analysis to work? I think of dynamic_cast<D*>(b)
as meaning roughly (*b instanceof D) ? static_cast<D*>(b) : nullptr
, but maybe that's an oversimplification? If the type check doesn't pass, then the returned pointer doesn't point to any object, but that's also sort of true for a static_cast
.
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.
The "sidecast" case in https://en.cppreference.com/w/cpp/language/dynamic_cast means that the offset is at least sometimes unknown
. Even for the downcast case, there isn't an unambiguous offset for a conversion from Y
to Base
in https://godbolt.org/z/ebWA7x
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.
There's also the special case of dynamic_cast<void*>
which casts to the most specific polymorphic class: https://godbolt.org/z/AZJpxS
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.
Thanks for the explanations. Inheritance is scary!
Adds taint propagation through
dynamic_cast
expressions