Browse Source

Catch bad file in readelf

K. Lange 2 years ago
parent
commit
0ac9adf3f0
1 changed files with 6 additions and 0 deletions
  1. 6 0
      apps/readelf.c

+ 6 - 0
apps/readelf.c

@@ -13,6 +13,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
+#include <errno.h>
 #include <kernel/elf.h>
 
 /**
@@ -46,6 +47,11 @@ int main(int argc, char ** argv) {
 	/* Open the requested binary */
 	binary = fopen(argv[1], "r");
 
+	if (!binary) {
+		fprintf(stderr, "%s: %s: %s\n", argv[0], argv[1], strerror(errno));
+		return 1;
+	}
+
 	/* Jump to the end so we can get the size */
 	fseek(binary, 0, SEEK_END);
 	binary_size = ftell(binary);