From 83e0bdad7a68b9a444dd55bcc23452987724c48c Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Sun, 28 Apr 2024 13:26:38 +0100 Subject: [PATCH 1/2] [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'. --- src/iso.c | 22 ++++++++++++++++------ src/rufus.rc | 10 +++++----- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/iso.c b/src/iso.c index 19683980..47733207 100644 --- a/src/iso.c +++ b/src/iso.c @@ -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) { 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 (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 // 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); // If not found in remainder and we have a remainder, loop to search from beginning - if (!found && md5sum_pos != md5sum_data) { - c[2] = *md5sum_pos; - *md5sum_pos = 0; + if (!found && pos != md5sum_data) { + nul_pos = pos; + c[2] = *nul_pos; + *nul_pos = 0; 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); } diff --git a/src/rufus.rc b/src/rufus.rc index a779ac89..4f354c5b 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.2146" +CAPTION "Rufus 4.5.2147" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -397,8 +397,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 4,5,2146,0 - PRODUCTVERSION 4,5,2146,0 + FILEVERSION 4,5,2147,0 + PRODUCTVERSION 4,5,2147,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -416,13 +416,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "4.5.2146" + VALUE "FileVersion", "4.5.2147" 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.2146" + VALUE "ProductVersion", "4.5.2147" END END BLOCK "VarFileInfo" From 2a6df95cad99f9a27e8def2abc13114a410b87a4 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Sun, 28 Apr 2024 13:56:18 +0100 Subject: [PATCH 2/2] [iso] fix persistence option not being added for Ubuntu 24.04 * Ubuntu changed their GRUB config format yet again, so our search for the kernel config no longer works, and the 'persistent' option doesn't get added. * Switch to a more generic '/casper/vmlinuz' search, though it might have unintended consequences... * Also fix a possible double free in FormatExtFs(). --- src/format_ext.c | 5 ++++- src/iso.c | 6 +++--- src/rufus.rc | 10 +++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/format_ext.c b/src/format_ext.c index 69983672..7209b817 100644 --- a/src/format_ext.c +++ b/src/format_ext.c @@ -491,7 +491,10 @@ BOOL FormatExtFs(DWORD DriveIndex, uint64_t PartitionOffset, DWORD BlockSize, LP // Finally we can call close() to get the file system gets created r = ext2fs_close(ext2fs); - if (r != 0) { + if (r == 0) { + // Make sure ext2fs isn't freed twice + ext2fs = NULL; + } else { SET_EXT2_FORMAT_ERROR(ERROR_WRITE_FAULT); uprintf("Could not create %s volume: %s", FSName, error_message(r)); goto out; diff --git a/src/iso.c b/src/iso.c index 47733207..a57f22ce 100644 --- a/src/iso.c +++ b/src/iso.c @@ -384,9 +384,9 @@ static void fix_config(const char* psz_fullpath, const char* psz_path, const cha if ((props->is_grub_cfg) && replace_in_token_data(src, "linux", "maybe-ubiquity", "", TRUE)) uprintf(" Removed 'maybe-ubiquity' kernel option"); - } else if (replace_in_token_data(src, "linux", "layerfs-path=minimal.standard.live.squashfs", - "persistent layerfs-path=minimal.standard.live.squashfs", TRUE) != NULL) { - // Ubuntu 23.04 uses GRUB only with the above and does not use "maybe-ubiquity" + } else if (replace_in_token_data(src, "linux", "/casper/vmlinuz", + "/casper/vmlinuz persistent", TRUE) != NULL) { + // Ubuntu 23.04 and 24.04 use GRUB only with the above and don't use "maybe-ubiquity" uprintf(" Added 'persistent' kernel option"); modified = TRUE; } else if (replace_in_token_data(src, props->is_grub_cfg ? "linux" : "append", diff --git a/src/rufus.rc b/src/rufus.rc index 4f354c5b..f656763d 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.2147" +CAPTION "Rufus 4.5.2148" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -397,8 +397,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 4,5,2147,0 - PRODUCTVERSION 4,5,2147,0 + FILEVERSION 4,5,2148,0 + PRODUCTVERSION 4,5,2148,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -416,13 +416,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "4.5.2147" + VALUE "FileVersion", "4.5.2148" 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.2147" + VALUE "ProductVersion", "4.5.2148" END END BLOCK "VarFileInfo"