shithub: rgbds

Download patch

ref: 2f35d10373f495544db4511dff818d88341960f0
parent: a397acd5eaf4db068988b5351c3d2a3cc16233bb
parent: 2dfd937d7f2c8d3ceaae5c471d7a2b0a342855b1
author: Anthony J. Bentley <anthony@cathet.us>
date: Sat Dec 1 17:46:21 EST 2012

Merge pull request #5 from vegard/lexer-fix-for-bentley

Prevent lexer from reading beyond the end of the buffer

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -392,6 +392,15 @@
 		hash = 0;
 		s = pLexBuffer;
 		while (yyleng < nLexMaxLeng) {
+			/* XXX: Kludge warning! The dereference of s below
+			 * may go beyond the end of the buffer. We use the
+			 * following test to stop that from happening,
+			 * without really understanding what the rest of
+			 * the code is doing. This may not be the correct
+			 * fix! */
+			if (!*s)
+				break;
+
 			yyleng += 1;
 			hash = ((hash << 1) + (toupper(*s))) % LEXHASHSIZE;
 			s += 1;