summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJia Zhouyang <jiazhouyang@nudt.edu.cn>2017-07-25 00:37:12 +0800
committerTobias Klauser <tklauser@distanz.ch>2017-07-25 08:54:47 +0200
commit9f87a7b3aa0ef520ec9f39c049cd8b947c73429e (patch)
tree95b14e558762c6cc33a0787e26bc9b10d7f31938
parent3261379f19ad0da4c32e8ab5654a84bf5d17282a (diff)
mausezahn: fix segmentation fault
Mausezahn will crash when given wrong payload file, e.g., "$./mausezahn -f wrong_file". This patch fixes the segmentation fault by adding error-handling code to fopen. Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--staging/mausezahn.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/staging/mausezahn.c b/staging/mausezahn.c
index ec3bc0e..4f312fd 100644
--- a/staging/mausezahn.c
+++ b/staging/mausezahn.c
@@ -518,6 +518,10 @@ int getopts (int argc, char *argv[])
break;
case 'f': // ASCII payload in FILE
afp = fopen(optarg, "r");
+ if (!afp) {
+ fprintf(stderr, " mz/getopts: Can not open file %s. %s!\n", optarg, strerror(errno));
+ return -1;
+ }
if (fgets((char*)tx.ascii_payload, MAX_PAYLOAD_SIZE, afp) == NULL)
fprintf(stderr, " mz/getopts: File empty?\n");
fclose(afp);
@@ -525,6 +529,10 @@ int getopts (int argc, char *argv[])
break;
case 'F': // HEX payload in FILE
afp = fopen(optarg, "r");
+ if (!afp) {
+ fprintf(stderr, " mz/getopts: Can not open file %s. %s!\n", optarg, strerror(errno));
+ return -1;
+ }
i=0;
while ( (hexpld[i]=fgetc(afp))!=EOF ) {
if (isspace(hexpld[i])) {