From 00ef44ac089d5238035142fdba0cbf00f1a6b3f5 Mon Sep 17 00:00:00 2001 From: gbrochar Date: Fri, 6 Sep 2024 21:42:55 +0200 Subject: [PATCH] fix: leaks --- src/woody_woodpacker.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/woody_woodpacker.c b/src/woody_woodpacker.c index fea9f8e..6e9ebca 100644 --- a/src/woody_woodpacker.c +++ b/src/woody_woodpacker.c @@ -116,6 +116,7 @@ int pack_elf64(t_map file) { t_payload64 payload = get_xor_payload64(); ft_printf("info: using %s algorithm\n", payload.algo_name); + free(payload.algo_name); // This should fallback to compression algorithm, or smaller payload (eg rsa->xor) if (payload.len > (size_t)code_cave.size) { printf("code cave size: %ld (0x%lx) bytes\n", code_cave.size, code_cave.size); @@ -140,20 +141,21 @@ int pack_elf64(t_map file) { } ft_memcpy(payload.data + payload.private_key_offset, key, sizeof(uint64_t)); payload.encrypt(file, key, *load_segment); + free(key); } - elf_header->e_entry = code_cave.data - file.data; load_segment->p_filesz += payload.len; load_segment->p_memsz += payload.len; load_segment->p_flags |= PF_W | PF_R; ft_memcpy(code_cave.data, payload.data, payload.len); + free(payload.data); int fd = open("woody", O_WRONLY | O_CREAT, 0755); if (fd == -1) { return wdy_perror("woody"); } write(fd, file.data, file.size); - + munmap(file.data, file.size); return RET_OK; }