switch (dynamic_section_entry->d_tag) {
case DT_VERNEEDED: removed_name = "DT_VERNEEDED"; break;
case DT_VERNEEDNUM: removed_name = "DT_VERNEEDNUM"; break;
+ case DT_VERDEF: removed_name = "DT_VERDEF"; break;
+ case DT_VERDEFNUM: removed_name = "DT_VERDEFNUM"; break;
case DT_RPATH: removed_name = "DT_RPATH"; break;
case DT_RUNPATH: removed_name = "DT_RUNPATH"; break;
}
for (int i = 1; i < argc; i++) {
char const* file_name = argv[i];
int fd = open(file_name, O_RDWR);
- if (fd < 0) { perror("open()"); return 1; }
+ if (fd < 0) {
+ char* error_message;
+ if (asprintf(&error_message, "open(\"%s\")", file_name) == -1) error_message = (char*) "open()";
+ perror(error_message);
+ return 1;
+ }
struct stat st;
if (fstat(fd, &st) < 0) { perror("fstat()"); return 1; }
- if (st.st_size < (long long) sizeof(Elf32_Ehdr)) continue;
+ if (st.st_size < (long long) sizeof(Elf32_Ehdr)) {
+ close(fd);
+ continue;
+ }
void* mem = mmap(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (mem == MAP_FAILED) { perror("mmap()"); return 1; }
if (bytes[/*EI_DATA*/5] != 1) {
fprintf(stderr, "termux-elf-cleaner: Not little endianness in '%s'\n", file_name);
+ munmap(mem, st.st_size);
+ close(fd);
continue;
}