Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Keystone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Third Party Mirrors
Keystone
Commits
b648ea82
Commit
b648ea82
authored
8 years ago
by
Nguyen Anh Quynh
Browse files
Options
Downloads
Patches
Plain Diff
x86: sanity check on Scale of memory operand. this fixes issue #154
parent
4d8f1962
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+26
-1
26 additions, 1 deletion
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
with
26 additions
and
1 deletion
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+
26
−
1
View file @
b648ea82
...
@@ -1263,7 +1263,8 @@ static unsigned getIntelMemOperandSize(StringRef OpStr) {
...
@@ -1263,7 +1263,8 @@ static unsigned getIntelMemOperandSize(StringRef OpStr) {
std
::
unique_ptr
<
X86Operand
>
X86AsmParser
::
CreateMemForInlineAsm
(
std
::
unique_ptr
<
X86Operand
>
X86AsmParser
::
CreateMemForInlineAsm
(
unsigned
SegReg
,
const
MCExpr
*
Disp
,
unsigned
BaseReg
,
unsigned
IndexReg
,
unsigned
SegReg
,
const
MCExpr
*
Disp
,
unsigned
BaseReg
,
unsigned
IndexReg
,
unsigned
Scale
,
SMLoc
Start
,
SMLoc
End
,
unsigned
Size
,
StringRef
Identifier
,
unsigned
Scale
,
SMLoc
Start
,
SMLoc
End
,
unsigned
Size
,
StringRef
Identifier
,
InlineAsmIdentifierInfo
&
Info
)
{
InlineAsmIdentifierInfo
&
Info
)
{
// If we found a decl other than a VarDecl, then assume it is a FuncDecl or
// If we found a decl other than a VarDecl, then assume it is a FuncDecl or
// some other label reference.
// some other label reference.
if
(
isa
<
MCSymbolRefExpr
>
(
Disp
)
&&
Info
.
OpDecl
&&
!
Info
.
IsVarDecl
)
{
if
(
isa
<
MCSymbolRefExpr
>
(
Disp
)
&&
Info
.
OpDecl
&&
!
Info
.
IsVarDecl
)
{
...
@@ -1588,6 +1589,18 @@ X86AsmParser::ParseIntelBracExpression(unsigned SegReg, SMLoc Start,
...
@@ -1588,6 +1589,18 @@ X86AsmParser::ParseIntelBracExpression(unsigned SegReg, SMLoc Start,
int
IndexReg
=
SM
.
getIndexReg
();
int
IndexReg
=
SM
.
getIndexReg
();
//printf("--- BaseReg = %u, IndexReg = %u, SegReg = %u\n", BaseReg, IndexReg, SegReg);
//printf("--- BaseReg = %u, IndexReg = %u, SegReg = %u\n", BaseReg, IndexReg, SegReg);
int
Scale
=
SM
.
getScale
();
int
Scale
=
SM
.
getScale
();
if
(
IndexReg
!=
0
&&
!
Scale
)
{
// Scale must go with Index register
KsError
=
KS_ERR_ASM_INVALIDOPERAND
;
return
nullptr
;
}
if
(
Scale
!=
1
&&
Scale
!=
2
&&
Scale
!=
4
&&
Scale
!=
8
)
{
// invalid Scale
KsError
=
KS_ERR_ASM_INVALIDOPERAND
;
return
nullptr
;
}
if
(
!
isParsingInlineAsm
())
{
if
(
!
isParsingInlineAsm
())
{
// handle [-42]
// handle [-42]
if
(
!
BaseReg
&&
!
IndexReg
)
{
if
(
!
BaseReg
&&
!
IndexReg
)
{
...
@@ -2381,6 +2394,18 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseMemOperand(unsigned SegReg,
...
@@ -2381,6 +2394,18 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseMemOperand(unsigned SegReg,
return
nullptr
;
return
nullptr
;
}
}
if
(
IndexReg
!=
0
&&
!
Scale
)
{
// Scale must go with Index register
KsError
=
KS_ERR_ASM_INVALIDOPERAND
;
return
nullptr
;
}
if
(
Scale
!=
1
&&
Scale
!=
2
&&
Scale
!=
4
&&
Scale
!=
8
)
{
// invalid Scale
KsError
=
KS_ERR_ASM_INVALIDOPERAND
;
return
nullptr
;
}
if
(
SegReg
||
BaseReg
||
IndexReg
)
if
(
SegReg
||
BaseReg
||
IndexReg
)
return
X86Operand
::
CreateMem
(
getPointerWidth
(),
SegReg
,
Disp
,
BaseReg
,
return
X86Operand
::
CreateMem
(
getPointerWidth
(),
SegReg
,
Disp
,
BaseReg
,
IndexReg
,
Scale
,
MemStart
,
MemEnd
);
IndexReg
,
Scale
,
MemStart
,
MemEnd
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment