Skip to content

Commit

Permalink
Add unit tests for process_lookup_path
Browse files Browse the repository at this point in the history
  • Loading branch information
ValekoZ committed Apr 20, 2024
1 parent b98eaca commit 3e591b8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/api/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ def test_func_show_last_exception(self):
gdb.execute("gef config gef.propagate_debug_exception True")
with pytest.raises(Exception):
gdb.execute("hexdump byte *0")

def test_func_process_lookup_path(self):
root, gdb = self._conn.root, self._gdb
gdb.execute("start")

assert root.eval("process_lookup_path('meh')") is None

libc = root.eval("process_lookup_path('libc')")
assert libc is not None
assert "libc" in pathlib.Path(libc.path).name

assert root.eval("process_lookup_path('stack')") is not None
4 changes: 4 additions & 0 deletions tests/binaries/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ all: $(LINKED)

%.out : %.c
@echo "[+] Building '$(TMPDIR)/$@'"
@mkdir -p $(TMPDIR)
@$(CC) $(CFLAGS) $(EXTRA_FLAGS) -o $(TMPDIR)/$@ $? $(LDFLAGS)

%.out : %.cpp
Expand Down Expand Up @@ -55,3 +56,6 @@ heap-non-main.out heap-tcache.out heap-multiple-heaps.out: EXTRA_FLAGS := -pthre
heap-bins.out: EXTRA_FLAGS := -Wno-unused-result

default.out: EXTRA_FLAGS := -fstack-protector-all -fpie -pie

collision.out: TMPDIR := $(TMPDIR)/collision-libc

16 changes: 16 additions & 0 deletions tests/binaries/collision.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* collision.c
* -*- mode: c -*-
* -*- coding: utf-8 -*-
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>


int main(int argc, char** argv, char** envp)
{
printf("Hello World!\n");
return EXIT_SUCCESS;
}
29 changes: 29 additions & 0 deletions tests/regressions/filename_collision_lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest

from tests.base import RemoteGefUnitTestGeneric
from tests.utils import debug_target


class RegressionFilenameCollisionLookup(RemoteGefUnitTestGeneric):
"""Tests for regression about collisions in filenames while using
`process_lookup_path`
"""

def setUp(self) -> None:
self._target = debug_target("collision-libc/collision")
return super().setUp()

def test_process_lookup_path_use_only_filename(self):
root, gdb = self._conn.root, self._gdb

gdb.execute("start")
program = root.eval("process_lookup_path('collision')")
libc = root.eval("process_lookup_path('libc')")

print(program)
print(libc)

assert program is not None
assert libc is not None
# TODO: Check if we can compare sections directly
assert program.page_start != libc.page_start

0 comments on commit 3e591b8

Please sign in to comment.