From 71c94cf7080b9a212c68075575fee46a7d133c3f Mon Sep 17 00:00:00 2001 From: masterzorag Date: Thu, 16 Aug 2018 10:36:06 +0200 Subject: [PATCH 1/4] Makefile: don't require exactly Clang 5.0 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 44bf904..53e30c6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -COMPILER= clang-5.0 +COMPILER= clang OUTPUTEXEC= orbisFixElf SOURCE_FILES= main.c myelf.c toolbox.c logger.c dyngen.c varray.c CFLAGS= -l elf -o @@ -7,4 +7,4 @@ all: $(COMPILER) $(SOURCE_FILES) $(CFLAGS) $(OUTPUTEXEC) clean: - rm $(OUTPUTEXEC) \ No newline at end of file + rm $(OUTPUTEXEC) From 272e4605d7bee14a2701dfacb71054a2862f06f7 Mon Sep 17 00:00:00 2001 From: masterzorag Date: Thu, 16 Aug 2018 10:40:31 +0200 Subject: [PATCH 2/4] fix: illegal write by 1 mallocated size was 1 byte smaller than used --- dyngen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dyngen.c b/dyngen.c index 9bbf689..15d61b5 100644 --- a/dyngen.c +++ b/dyngen.c @@ -116,7 +116,7 @@ struct orbis_comment generate_sce_comment(char *path) void *consolidate_orbis_comment(struct orbis_comment ioc) { int size_of_path = strlen(ioc.path); - int projected_size = (size_of_path + 16); + int projected_size = (size_of_path + 16 + 1); int current_size; void *tempBuff = malloc(projected_size); From b16f1bd58c86ff8b1961d92b20884b7f645f20e4 Mon Sep 17 00:00:00 2001 From: masterzorag Date: Thu, 16 Aug 2018 10:42:40 +0200 Subject: [PATCH 3/4] fix: uninitiated value is used to take counting --- dyngen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dyngen.c b/dyngen.c index 15d61b5..bf6d3c7 100644 --- a/dyngen.c +++ b/dyngen.c @@ -117,8 +117,8 @@ void *consolidate_orbis_comment(struct orbis_comment ioc) { int size_of_path = strlen(ioc.path); int projected_size = (size_of_path + 16 + 1); - int current_size; - + int current_size = 0; + void *tempBuff = malloc(projected_size); memcpy(tempBuff, &ioc.Magic, sizeof(ioc.Magic)+1); From 628c7000147ec76a5d4fdc92822181bdf5e5c60d Mon Sep 17 00:00:00 2001 From: masterzorag Date: Thu, 16 Aug 2018 10:58:42 +0200 Subject: [PATCH 4/4] fix: avoid memory leaks --- main.c | 7 ++++--- toolbox.c | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 440531f..519967b 100644 --- a/main.c +++ b/main.c @@ -191,9 +191,10 @@ int main(int argc, char **argv) // CREATE SCE COMMENT SECTION Elf_Scn *testScn = orb_create_section(&importElf, ".sce_comment", oelf_comment_section, (size_t)projected_size_of_section); - - - + // cleanup + if(oelf_comment_section) free(oelf_comment_section), oelf_comment_section = NULL; + varray_destroy(&importElf.fstubs_va); + varray_destroy(&importElf.vstubs_va); } else { diff --git a/toolbox.c b/toolbox.c index 78a958f..b02aa1d 100644 --- a/toolbox.c +++ b/toolbox.c @@ -229,6 +229,9 @@ Elf_Scn *orb_create_section(OrbisElf *inputElf, const char *name, void *scnData, shdr.sh_name = shstrtab_shdr.sh_size; shstrtab_shdr.sh_size += shstrtab_data->d_size; + + // cleanup + free(shstrtab_data->d_buf), shstrtab_data->d_buf = NULL; if(!gelf_update_shdr(new_scn, &shdr)) {