소스 검색

Fix read past end of buffer after call to TokenMatch

IsSpaceOrNewLine returns true on end of input (NUL character). But if
TokenMatch considers a token at end of input to match it sets "in" to
one past end of buffer. This will lead to reading past the end of
buffer on any subsequent operation.
Turo Lamminen 10 년 전
부모
커밋
c342778f42
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      code/ParsingUtils.h

+ 5 - 0
code/ParsingUtils.h

@@ -201,7 +201,12 @@ template <class char_t>
 AI_FORCE_INLINE bool TokenMatch(char_t*& in, const char* token, unsigned int len)
 {
 	if (!::strncmp(token,in,len) && IsSpaceOrNewLine(in[len])) {
+		if (in[len] != '\0') {
 		in += len+1;
+		} else {
+			// If EOF after the token make sure we don't go past end of buffer
+			in += len;
+		}
 		return true;
 	}