diff --git a/src/hash.c b/src/hash.c index 3f2c0df6..53a9c18d 100644 --- a/src/hash.c +++ b/src/hash.c @@ -97,20 +97,6 @@ #define BUFFER_SIZE (64*KB) #define WAIT_TIME 5000 -/* Blocksize for each algorithm - Must be a power of 2 */ -#define MD5_BLOCKSIZE 64 -#define SHA1_BLOCKSIZE 64 -#define SHA256_BLOCKSIZE 64 -#define SHA512_BLOCKSIZE 128 -#define MAX_BLOCKSIZE SHA512_BLOCKSIZE - -/* Hashsize for each algorithm */ -#define MD5_HASHSIZE 16 -#define SHA1_HASHSIZE 20 -#define SHA256_HASHSIZE 32 -#define SHA512_HASHSIZE 64 -#define MAX_HASHSIZE SHA512_HASHSIZE - /* Number of buffers we work with */ #define NUM_BUFFERS 3 // 2 + 1 as a mere double buffered async I/O // would modify the buffer being processed. @@ -178,16 +164,6 @@ static const uint64_t K512[80] = { 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL }; -/* - * For convenience, we use a common context for all the hash algorithms, - * which means some elements may be unused... - */ -typedef struct ALIGNED(64) { - uint8_t buf[MAX_BLOCKSIZE]; - uint64_t state[8]; - uint64_t bytecount; -} HASH_CONTEXT; - static void md5_init(HASH_CONTEXT *ctx) { memset(ctx, 0, sizeof(*ctx)); @@ -1467,9 +1443,6 @@ static void null_write(HASH_CONTEXT *ctx, const uint8_t *buf, size_t len) { } static void null_final(HASH_CONTEXT *ctx) { } #endif -typedef void hash_init_t(HASH_CONTEXT *ctx); -typedef void hash_write_t(HASH_CONTEXT *ctx, const uint8_t *buf, size_t len); -typedef void hash_final_t(HASH_CONTEXT *ctx); hash_init_t *hash_init[HASH_MAX] = { md5_init, sha1_init , sha256_init, sha512_init }; hash_write_t *hash_write[HASH_MAX] = { md5_write, sha1_write , sha256_write, sha512_write }; hash_final_t *hash_final[HASH_MAX] = { md5_final, sha1_final , sha256_final, sha512_final }; diff --git a/src/missing.h b/src/missing.h index 88dc116c..57bee44b 100644 --- a/src/missing.h +++ b/src/missing.h @@ -31,14 +31,14 @@ #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif +#ifndef MAX +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif + #define LO_ALIGN_X_TO_Y(x, y) (((x) / (y)) * (y)) #define HI_ALIGN_X_TO_Y(x, y) ((((x) + (y) - 1) / (y)) * (y)) -#if defined(__GNUC__) -#define ALIGNED(m) __attribute__ ((__aligned__(m))) -#elif defined(_MSC_VER) -#define ALIGNED(m) __declspec(align(m)) -#endif +#define IS_HEXASCII(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) /* * Prefetch 64 bytes at address m, for read-only operation diff --git a/src/process.c b/src/process.c index 9511808e..1027ee54 100644 --- a/src/process.c +++ b/src/process.c @@ -499,8 +499,8 @@ static DWORD WINAPI SearchProcessThread(LPVOID param) goto out; } if (wHandleName != NULL) { - for (i = 0; i < nHandles; i++) - free(wHandleName[i]); + for (j = 0; j < nHandles; j++) + free(wHandleName[j]); free(wHandleName); } safe_free(wHandleNameLen); @@ -515,10 +515,10 @@ static DWORD WINAPI SearchProcessThread(LPVOID param) ReleaseMutex(hLock); goto out; } - for (i = 0; i < nHandles; i++) { - wHandleName[i] = wcsdup(blocking_process.wHandleName[i]); - wHandleNameLen[i] = (USHORT)wcslen(blocking_process.wHandleName[i]); - if (wHandleName[i] == NULL) { + for (j = 0; j < nHandles; j++) { + wHandleName[j] = wcsdup(blocking_process.wHandleName[j]); + wHandleNameLen[j] = (USHORT)wcslen(blocking_process.wHandleName[j]); + if (wHandleName[j] == NULL) { ReleaseMutex(hLock); goto out; } @@ -741,8 +741,8 @@ out: uprintf("Warning: Could not start process handle enumerator!"); if (wHandleName != NULL) { - for (i = 0; i < nHandles; i++) - free(wHandleName[i]); + for (j = 0; j < nHandles; j++) + free(wHandleName[j]); free(wHandleName); } safe_free(wHandleNameLen); diff --git a/src/rufus.h b/src/rufus.h index c22da925..800a7a39 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -311,14 +311,6 @@ enum image_option_type { IMOP_MAX }; -enum hash_type { - HASH_MD5 = 0, - HASH_SHA1, - HASH_SHA256, - HASH_SHA512, - HASH_MAX -}; - enum file_io_type { FILE_IO_READ = 0, FILE_IO_WRITE, @@ -484,6 +476,51 @@ typedef struct { uint32_t* address; // 32-bit will do, as we're not dealing with >4GB DLLs... } dll_resolver_t; +/* Alignment macro */ +#if defined(__GNUC__) +#define ALIGNED(m) __attribute__ ((__aligned__(m))) +#elif defined(_MSC_VER) +#define ALIGNED(m) __declspec(align(m)) +#endif + +/* Hash definitions */ +enum hash_type { + HASH_MD5 = 0, + HASH_SHA1, + HASH_SHA256, + HASH_SHA512, + HASH_MAX +}; + +/* Blocksize for each hash algorithm - Must be a power of 2 */ +#define MD5_BLOCKSIZE 64 +#define SHA1_BLOCKSIZE 64 +#define SHA256_BLOCKSIZE 64 +#define SHA512_BLOCKSIZE 128 +#define MAX_BLOCKSIZE SHA512_BLOCKSIZE + +/* Hashsize for each hash algorithm */ +#define MD5_HASHSIZE 16 +#define SHA1_HASHSIZE 20 +#define SHA256_HASHSIZE 32 +#define SHA512_HASHSIZE 64 +#define MAX_HASHSIZE SHA512_HASHSIZE + +/* Context for the hash algorithms */ +typedef struct ALIGNED(64) { + uint8_t buf[MAX_BLOCKSIZE]; + uint64_t state[8]; + uint64_t bytecount; +} HASH_CONTEXT; + +/* Hash functions */ +typedef void hash_init_t(HASH_CONTEXT* ctx); +typedef void hash_write_t(HASH_CONTEXT* ctx, const uint8_t* buf, size_t len); +typedef void hash_final_t(HASH_CONTEXT* ctx); +extern hash_init_t* hash_init[HASH_MAX]; +extern hash_write_t* hash_write[HASH_MAX]; +extern hash_final_t* hash_final[HASH_MAX]; + #ifndef __VA_GROUP__ #define __VA_GROUP__(...) __VA_ARGS__ #endif diff --git a/src/rufus.rc b/src/rufus.rc index e837f416..22d6d612 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 232, 326 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 4.5.2117" +CAPTION "Rufus 4.5.2118" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -392,8 +392,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 4,5,2117,0 - PRODUCTVERSION 4,5,2117,0 + FILEVERSION 4,5,2118,0 + PRODUCTVERSION 4,5,2118,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -411,13 +411,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "4.5.2117" + VALUE "FileVersion", "4.5.2118" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2024 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "OriginalFilename", "rufus-4.5.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "4.5.2117" + VALUE "ProductVersion", "4.5.2118" END END BLOCK "VarFileInfo" diff --git a/src/stdio.c b/src/stdio.c index 7a52a6fe..88ca20c2 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -125,7 +125,8 @@ uint32_t read_file(const char* path, uint8_t** buf) uint32_t size = (uint32_t)ftell(fd); fseek(fd, 0L, SEEK_SET); - *buf = malloc(size); + // +1 so we can add an extra NUL + *buf = malloc(size + 1); if (*buf == NULL) { uprintf("Error: Can't allocate %d bytes buffer for file '%s'", size, path); size = 0; @@ -135,6 +136,8 @@ uint32_t read_file(const char* path, uint8_t** buf) uprintf("Error: Can't read '%s'", path); size = 0; } + // Always NUL terminate the file + (*buf)[size] = 0; out: fclose(fd);