Skip to content

Commit

Permalink
unpackbootimg: "second_signature" fixes
Browse files Browse the repository at this point in the history
- simplify filesize check since we already have the filename
- add check to workaround 4-byte nul false positives on some files
- add missing include that may be required in some build environments
  • Loading branch information
osm0sis committed Apr 28, 2017
1 parent af98839 commit 4ecff2c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions unpackbootimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <errno.h>
#include <limits.h>
#include <libgen.h>
#include <sys/stat.h>

#include "mincrypt/sha.h"
#include "bootimg.h"
Expand Down Expand Up @@ -269,9 +270,8 @@ int main(int argc, char** argv)
* size based on termination with a null, then fix it in header.
*/
if (header.second_size == 0) {
int fd = fileno(f);
struct stat st;
fstat(fd, &st);
stat(filename, &st);
int second_test_size = st.st_size - total_read;
byte* second_test = (byte*)malloc(second_test_size);
if(fread(second_test, second_test_size, 1, f)){};
Expand All @@ -282,7 +282,8 @@ int main(int argc, char** argv)
second_size += 2;
sbuf++;
}
header.second_size = second_size;
if (second_size > 4)
header.second_size = second_size;
}
fseek(f, total_read, SEEK_SET);
}
Expand Down

0 comments on commit 4ecff2c

Please sign in to comment.