Skip to content

Commit 5a98545

Browse files
committed
Can't use trampolines for data symbols.
Verify that the page containing the target symbol is marked executable before creating a trampoline.
1 parent 4ab8953 commit 5a98545

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

flexdll.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ static void relocate(resolver f, void *data, reloctbl *tbl, void **jmptbl) {
186186
char* reloc_type;
187187
/*
188188
DWORD old;
189-
MEMORY_BASIC_INFORMATION info;
190189
*/
190+
MEMORY_BASIC_INFORMATION info;
191191

192192
if (!tbl) return;
193193

@@ -249,6 +249,12 @@ static void relocate(resolver f, void *data, reloctbl *tbl, void **jmptbl) {
249249
if (s != (INT32) s) {
250250
if (jmptbl) {
251251
if (!sym->trampoline) {
252+
/* trampolines cannot be created for data */
253+
if (VirtualQuery(sym->addr, &info, sizeof(info)) && !(info.Protect & 0xf0)) {
254+
sprintf(error_buffer, "flexdll error: cannot relocate RELOC_REL32%s, target is too far, and not executable: %p %p", reloc_type, (void *)((UINT_PTR) s), (void *) ((UINT_PTR)(INT32) s));
255+
error = 3;
256+
return;
257+
}
252258
void* trampoline = sym->trampoline = *jmptbl;
253259
/* movq $(sym->addr), %rax */
254260
*((short*)trampoline) = 0xb848;

0 commit comments

Comments
 (0)