Skip to content

Commit b59068c

Browse files
committed
Fix obscure SEGV
(requires invalid JSON to trigger)
1 parent 9600908 commit b59068c

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ release: $(E9PATCH_OBJS)
3737
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch $(LDFLAGS)
3838
strip e9patch
3939

40-
debug: CXXFLAGS += -O0 -g -fsanitize=address
40+
debug: CXXFLAGS += -O0 -g
4141
debug: $(E9PATCH_OBJS)
4242
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
4343

44+
sanitize: CXXFLAGS += -O0 -g -fsanitize=address
45+
sanitize: $(E9PATCH_OBJS)
46+
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
47+
4448
tool: CXXFLAGS += -O2 -I src/e9tool/ -I zydis/include/ \
4549
-I zydis/dependencies/zycore/include/ -Wno-unused-function
4650
tool: $(E9TOOL_OBJS)
@@ -49,9 +53,15 @@ tool: $(E9TOOL_OBJS)
4953
strip e9tool
5054

5155
tool.debug: CXXFLAGS += -O0 -g -I src/e9tool/ -I zydis/include/ \
56+
-I zydis/dependencies/zycore/include/ -Wno-unused-function
57+
tool.debug: $(E9TOOL_OBJS)
58+
$(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) -o e9tool libZydis.a \
59+
-Wl,--dynamic-list=src/e9tool/e9tool.syms -ldl
60+
61+
tool.sanitize: CXXFLAGS += -O0 -g -I src/e9tool/ -I zydis/include/ \
5262
-I zydis/dependencies/zycore/include/ -Wno-unused-function \
5363
-fsanitize=address
54-
tool.debug: $(E9TOOL_OBJS)
64+
tool.sanitize: $(E9TOOL_OBJS)
5565
$(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) -o e9tool libZydis.a \
5666
-Wl,--dynamic-list=src/e9tool/e9tool.syms -ldl
5767

src/e9patch/e9x86_64.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ int relocateInstr(intptr_t addr, int32_t offset32, const uint8_t *bytes,
392392

393393
// Normal case:
394394
buf->push(modRM);
395-
if (mod == 0x0 && rm == 0x05)
395+
if (mod == 0x0 && rm == 0x05 &&
396+
size - i - 1 >= sizeof(uint32_t))
396397
{
397398
// This is a %rip-relative call, so we must adjust
398399
int32_t pcrel32 = *(uint32_t *)(bytes + i + 1);
@@ -591,7 +592,7 @@ int relocateInstr(intptr_t addr, int32_t offset32, const uint8_t *bytes,
591592
uint32_t modRM = bytes[i++];
592593
uint8_t mod = (modRM & 0xc0) >> 6;
593594
uint8_t rm = modRM & 0x7;
594-
if (mod == 0x0 && rm == 0x05)
595+
if (mod == 0x0 && rm == 0x05 && size - i >= sizeof(uint32_t))
595596
{
596597
// i points to a %rip-relative displacement. We adjust accordingly.
597598
int32_t pcrel32 = *(uint32_t *)(bytes + i);

0 commit comments

Comments
 (0)