From bb2d8536f52c241eea850a53263c950c34ef9652 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 18 Apr 2008 21:26:41 -0400 Subject: [PATCH] Prevent segfault on bogus instruction token. --HG-- branch : trunk --- mojoshader.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 3b8150aa..04420c5e 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -3809,6 +3809,7 @@ static const Instruction instructions[] = static int parse_instruction_token(Context *ctx) { + int retval = NOFAIL; const uint32 *start_tokens = ctx->tokens; const uint32 start_tokencount = ctx->tokencount; const uint32 token = SWAP32(*(ctx->tokens)); @@ -3817,13 +3818,13 @@ static int parse_instruction_token(Context *ctx) const uint32 insttoks = ((token >> 24) & 0x0F); const int coissue = (token & 0x40000000) ? 1 : 0; const int predicated = (token & 0x10000000) ? 1 : 0; - const Instruction *instruction = &instructions[opcode]; - const emit_function emitter = instruction->emitter[ctx->profileid]; - int retval = NOFAIL; if ( opcode >= (sizeof (instructions) / sizeof (instructions[0])) ) return 0; // not an instruction token, or just not handled here. + const Instruction *instruction = &instructions[opcode]; + const emit_function emitter = instruction->emitter[ctx->profileid]; + if ((token & 0x80000000) != 0) return fail(ctx, "instruction token high bit must be zero."); // so says msdn.