Skip to content
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

Do not use ZYAN_ASSERT for user passed arguments #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/Zydis/DecoderTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1253,9 +1253,11 @@ typedef struct ZydisDecodedInstruction_
typedef struct ZydisDecoderContext_
{
/**
* A pointer to the internal instruction definition.
* The instruction definition id.
*
* Only valid in combination with the instruction encoding.
*/
const void* definition;
ZyanU16 definition_id;
Copy link
Member Author

Choose a reason for hiding this comment

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

This change allows us to actually fuzz the code (open todo) and as well guarantees we never read invalid memory, even if the user passes nonsense data.

Copy link
Member

Choose a reason for hiding this comment

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

And all while requiring less space in the struct! Nice.

/**
* Contains the effective operand-size index.
*
Expand Down
3 changes: 3 additions & 0 deletions include/Zydis/Internal/DecoderData.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ typedef struct ZydisDecoderTreeNode_
ZydisDecoderTreeNodeValue value;
} ZydisDecoderTreeNode;

// See `ZydisDecoderContext.instruction_id`
ZYAN_STATIC_ASSERT(sizeof(ZydisDecoderTreeNodeValue) == sizeof(ZyanU16));

/* ---------------------------------------------------------------------------------------------- */

#pragma pack(pop)
Expand Down