ref: 138523570e1b8a6a4e45f5c64a4335807c37c657
parent: 82469ac0fde1b2e73bfbfc58853a7ecb95e4a794
author: ISSOtm <[email protected]>
date: Mon Aug 31 10:47:55 EDT 2020
Fix possible uninitialized read on Windows
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -320,6 +320,7 @@
# include <winbase.h>
# define MAP_FAILED NULL
# define mapFile(ptr, fd, path, size) do { \
+ (ptr) = MAP_FAILED; \
HANDLE file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
FILE_FLAG_POSIX_SEMANTICS | FILE_FLAG_RANDOM_ACCESS, NULL); \
HANDLE mappingObj; \
@@ -327,9 +328,8 @@
if (file == INVALID_HANDLE_VALUE) \
break; \
mappingObj = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL); \
- (ptr) = mappingObj == INVALID_HANDLE_VALUE \
- ? NULL \
- : MapViewOfFile(mappingObj, FILE_MAP_READ, 0, 0, 0); \
+ if (mappingObj != INVALID_HANDLE_VALUE) \
+ (ptr) = MapViewOfFile(mappingObj, FILE_MAP_READ, 0, 0, 0); \
CloseHandle(mappingObj); \
CloseHandle(file); \
} while (0)