Skip to content

Commit

Permalink
fix Issue 2617 - asm silently accepts ambiguous-sized operations
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Aug 21, 2020
1 parent 9cb3a52 commit 8b5785d
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/dmd/iasmdmd.d
Expand Up @@ -773,14 +773,15 @@ RETRY:

case 1:
{
//printf("opflags1 = "); asm_output_flags(opflags1); printf("\n");
enum log = false;
if (log) { printf("opflags1 = "); asm_output_flags(opflags[0]); printf("\n"); }
PTRNTAB1 *table1;
for (table1 = pop.ptb.pptb1; table1.opcode != ASM_END;
table1++)
{
//printf("table = "); asm_output_flags(table1.usOp1); printf("\n");
if (log) { printf("table = "); asm_output_flags(table1.usOp1); printf("\n"); }
const bMatch1 = asm_match_flags(opflags[0], table1.usOp1);
//printf("bMatch1 = x%x\n", bMatch1);
if (log) { printf("bMatch1 = x%x\n", bMatch1); }
if (bMatch1)
{
if (table1.opcode == 0x68 &&
Expand All @@ -796,6 +797,16 @@ RETRY:
continue;
}

// Check for ambiguous size
if (getOpndSize(opflags[0]) == OpndSize._anysize &&
!opnds[0].bPtr &&
(table1 + 1).opcode != ASM_END &&
getOpndSize(table1.usOp1) == OpndSize._8)
{
asmerr("operand size for opcode `%s` is ambiguous, add `ptr byte/short/int/long` prefix", asm_opstr(pop));
break RETRY;
}

break;
}
if ((asmstate.ucItype == ITimmed) &&
Expand Down Expand Up @@ -896,8 +907,22 @@ RETRY:
}
}
}

// Check for ambiguous size
if (getOpndSize(opflags[0]) == OpndSize._anysize &&
!opnds[0].bPtr &&
opflags[1] == 0 &&
table2.usOp2 == 0 &&
(table2 + 1).opcode != ASM_END &&
getOpndSize(table2.usOp1) == OpndSize._8)
{
asmerr("operand size for opcode `%s` is ambiguous, add `ptr byte/short/int/long` prefix", asm_opstr(pop));
break RETRY;
}

break;
}

if (asmstate.ucItype == ITopt ||
asmstate.ucItype == ITfloat)
{
Expand Down

0 comments on commit 8b5785d

Please sign in to comment.