diff options
-rw-r--r-- | win32/mingw.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 26b046f1a..98254fdbe 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -473,16 +473,20 @@ static int has_exec_format(const char *name) | |||
473 | * the magic from the file command. | 473 | * the magic from the file command. |
474 | */ | 474 | */ |
475 | if (buf[0] == 'M' && buf[1] == 'Z') { | 475 | if (buf[0] == 'M' && buf[1] == 'Z') { |
476 | /* Convert four unsigned bytes to an unsigned int (little-endian) */ | ||
477 | #define LE4(b, o) (((unsigned)b[o+3] << 24) + (b[o+2] << 16) + \ | ||
478 | (b[o+1] << 8) + b[o]) | ||
479 | |||
476 | /* Actually Portable Executable */ | 480 | /* Actually Portable Executable */ |
477 | /* See ape/ape.S at https://github.com/jart/cosmopolitan */ | 481 | /* See ape/ape.S at https://github.com/jart/cosmopolitan */ |
478 | if (n > 9 && memcmp(buf + 2, "qFpD='\n", 7) == 0) | 482 | const unsigned char *qFpD = (unsigned char *)"qFpD"; |
483 | if (n > 6 && LE4(buf, 2) == LE4(qFpD, 0)) | ||
479 | return 1; | 484 | return 1; |
480 | 485 | ||
481 | if (n > 0x3f) { | 486 | if (n > 0x3f) { |
482 | offset = (buf[0x19] << 8) + buf[0x18]; | 487 | offset = (buf[0x19] << 8) + buf[0x18]; |
483 | if (offset > 0x3f) { | 488 | if (offset > 0x3f) { |
484 | offset = (buf[0x3f] << 24) + (buf[0x3e] << 16) + | 489 | offset = LE4(buf, 0x3c); |
485 | (buf[0x3d] << 8) + buf[0x3c]; | ||
486 | if (offset < sizeof(buf)-100) { | 490 | if (offset < sizeof(buf)-100) { |
487 | if (memcmp(buf+offset, "PE\0\0", 4) == 0) { | 491 | if (memcmp(buf+offset, "PE\0\0", 4) == 0) { |
488 | sig = (buf[offset+25] << 8) + buf[offset+24]; | 492 | sig = (buf[offset+25] << 8) + buf[offset+24]; |