1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[md5sum] fix unwanted partial matches in is_in_md5sum()

* is_in_md5sum() could partially match a string against another one, which, aside from matching
  unwanted files, could also lead to files not being identified as being in the md5sum.txt if
  the previous partial match happened to be with the current search target.
* Fix this by making sure that we always match a whole path followed by '/n', '/r' or '/0'.
This commit is contained in:
Pete Batard 2024-04-28 13:26:38 +01:00
parent df9e333f3a
commit 83e0bdad7a
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
2 changed files with 21 additions and 11 deletions

View file

@ -493,7 +493,7 @@ static void fix_config(const char* psz_fullpath, const char* psz_path, const cha
static BOOL is_in_md5sum(char* path) static BOOL is_in_md5sum(char* path)
{ {
BOOL found = FALSE; BOOL found = FALSE;
char c[3], *p; char c[3], *p, *pos = md5sum_pos, *nul_pos;
// If we are creating the md5sum file from scratch, every file is in it. // If we are creating the md5sum file from scratch, every file is in it.
if (fd_md5sum != NULL) if (fd_md5sum != NULL)
@ -514,14 +514,24 @@ static BOOL is_in_md5sum(char* path)
// Search for the string in the remainder of the md5sum.txt // Search for the string in the remainder of the md5sum.txt
// NB: md5sum_data is always NUL terminated. // NB: md5sum_data is always NUL terminated.
p = strstr(md5sum_pos, path); p = strstr(pos, path);
// Cater for the case where we matched a partial string and look for the full one
while (p != NULL && p[strlen(path)] != '\n' && p[strlen(path)] != '\r' && p[strlen(path)] != '\0') {
pos = p + strlen(path);
p = strstr(pos, path);
}
found = (p != NULL); found = (p != NULL);
// If not found in remainder and we have a remainder, loop to search from beginning // If not found in remainder and we have a remainder, loop to search from beginning
if (!found && md5sum_pos != md5sum_data) { if (!found && pos != md5sum_data) {
c[2] = *md5sum_pos; nul_pos = pos;
*md5sum_pos = 0; c[2] = *nul_pos;
*nul_pos = 0;
p = strstr(md5sum_data, path); p = strstr(md5sum_data, path);
*md5sum_pos = c[2]; while (p != NULL && p[strlen(path)] != '\n' && p[strlen(path)] != '\r' && p[strlen(path)] != '\0') {
pos = p + strlen(path);
p = strstr(pos, path);
}
*nul_pos = c[2];
found = (p != NULL); found = (p != NULL);
} }

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 4.5.2146" CAPTION "Rufus 4.5.2147"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -397,8 +397,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 4,5,2146,0 FILEVERSION 4,5,2147,0
PRODUCTVERSION 4,5,2146,0 PRODUCTVERSION 4,5,2147,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -416,13 +416,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie" VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "4.5.2146" VALUE "FileVersion", "4.5.2147"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "<22> 2011-2024 Pete Batard (GPL v3)" VALUE "LegalCopyright", "<22> 2011-2024 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-4.5.exe" VALUE "OriginalFilename", "rufus-4.5.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "4.5.2146" VALUE "ProductVersion", "4.5.2147"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"