From 90dc847e24b693c90e1dcd44077901bca0f2ea66 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Thu, 10 Aug 2017 19:43:04 +0100 Subject: [PATCH] [misc] add static_strcat & static_strcpy and use static_ calls wherever possible * Also set Rufus next to 2.17 and fix a warning --- configure | 20 ++++++++--------- configure.ac | 2 +- res/appstore/AppxManifest.xml | 2 +- res/appstore/packme.cmd | 2 +- src/dev.c | 16 +++++++------- src/dos.c | 14 ++++++------ src/dos_locale.c | 12 +++++----- src/drive.c | 6 ++--- src/format.c | 24 ++++++++++---------- src/icon.c | 2 +- src/iso.c | 30 ++++++++++++------------- src/net.c | 8 +++---- src/process.c | 4 ++-- src/registry.h | 8 +++---- src/rufus.c | 41 +++++++++++++++++------------------ src/rufus.h | 2 ++ src/rufus.rc | 10 ++++----- src/settings.h | 2 +- src/smart.c | 2 +- src/stdfn.c | 10 ++++----- src/stdio.c | 8 +++---- src/stdlg.c | 6 ++--- src/vhd.c | 10 ++++----- 23 files changed, 121 insertions(+), 120 deletions(-) diff --git a/configure b/configure index 4f721934..535b2d0a 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for rufus 2.16. +# Generated by GNU Autoconf 2.69 for rufus 2.17. # # Report bugs to . # @@ -580,8 +580,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='rufus' PACKAGE_TARNAME='rufus' -PACKAGE_VERSION='2.16' -PACKAGE_STRING='rufus 2.16' +PACKAGE_VERSION='2.17' +PACKAGE_STRING='rufus 2.17' PACKAGE_BUGREPORT='https://github.com/pbatard/rufus/issues' PACKAGE_URL='https://rufus.akeo.ie' @@ -1228,7 +1228,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures rufus 2.16 to adapt to many kinds of systems. +\`configure' configures rufus 2.17 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1294,7 +1294,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of rufus 2.16:";; + short | recursive ) echo "Configuration of rufus 2.17:";; esac cat <<\_ACEOF @@ -1385,7 +1385,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -rufus configure 2.16 +rufus configure 2.17 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1440,7 +1440,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by rufus $as_me 2.16, which was +It was created by rufus $as_me 2.17, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2303,7 +2303,7 @@ fi # Define the identity of the package. PACKAGE='rufus' - VERSION='2.16' + VERSION='2.17' cat >>confdefs.h <<_ACEOF @@ -4483,7 +4483,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by rufus $as_me 2.16, which was +This file was extended by rufus $as_me 2.17, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4537,7 +4537,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -rufus config.status 2.16 +rufus config.status 2.17 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 83399a5b..339ab2aa 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([rufus], [2.16], [https://github.com/pbatard/rufus/issues], [rufus], [https://rufus.akeo.ie]) +AC_INIT([rufus], [2.17], [https://github.com/pbatard/rufus/issues], [rufus], [https://rufus.akeo.ie]) AM_INIT_AUTOMAKE([-Wno-portability foreign no-dist no-dependencies]) AC_CONFIG_SRCDIR([src/rufus.c]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/res/appstore/AppxManifest.xml b/res/appstore/AppxManifest.xml index 2aeb1e97..88e18572 100644 --- a/res/appstore/AppxManifest.xml +++ b/res/appstore/AppxManifest.xml @@ -8,7 +8,7 @@ for an interesting struggle, when you also happen to have a comma in one of the fields... --> diff --git a/res/appstore/packme.cmd b/res/appstore/packme.cmd index 738e3c7a..11e33f84 100644 --- a/res/appstore/packme.cmd +++ b/res/appstore/packme.cmd @@ -1,5 +1,5 @@ @echo off -set VERSION=2.16 +set VERSION=2.17 rem Make sure you don't have anything you don't want included in the package, as anything residing in the rem current directory will be included, including any previous .appx, which makes for nice recursion... diff --git a/src/dev.c b/src/dev.c index 3297c8c6..c4568677 100644 --- a/src/dev.c +++ b/src/dev.c @@ -184,7 +184,7 @@ BOOL GetOpticalMedia(IMG_SAVE* img_save) if (!SetupDiGetDeviceRegistryPropertyU(dev_info, &dev_info_data, SPDRP_FRIENDLYNAME, &datatype, (LPBYTE)str, sizeof(str), &size)) { uprintf("SetupDiGetDeviceRegistryProperty (Friendly Name) failed: %s\n", WindowsErrorString()); - safe_strcpy(str, sizeof(str), "Generic Optical Drive"); + static_strcpy(str, "Generic Optical Drive"); } uprintf("Found '%s' optical device", str); devint_data.cbSize = sizeof(devint_data); @@ -245,7 +245,7 @@ BOOL GetOpticalMedia(IMG_SAVE* img_save) label[k] = 0; img_save->Label = label; } - safe_strcpy(str, sizeof(str), devint_detail_data->DevicePath); + static_strcpy(str, devint_detail_data->DevicePath); img_save->DevicePath = str; img_save->DeviceSize = DiskGeometry->DiskSize.QuadPart; safe_closehandle(hDrive); @@ -507,7 +507,7 @@ BOOL GetDevices(DWORD devnum) &datatype, (LPBYTE)buffer, sizeof(buffer), &size)) { uprintf("SetupDiGetDeviceRegistryProperty (Friendly Name) failed: %s\n", WindowsErrorString()); // We can afford a failure on this call - just replace the name with "USB Storage Device (Generic)" - safe_strcpy(buffer, sizeof(buffer), lmprintf(MSG_045)); + static_strcpy(buffer, lmprintf(MSG_045)); } else if ((!props.is_VHD) && (devid_list != NULL)) { // Get the properties of the device. We could avoid doing this lookup every time by keeping // a lookup table, but there shouldn't be that many USB storage devices connected... @@ -580,7 +580,7 @@ BOOL GetDevices(DWORD devnum) #ifdef FORCED_DEVICE props.vid = FORCED_VID; props.pid = FORCED_PID; - safe_strcpy(buffer, sizeof(buffer), FORCED_NAME); + static_strcpy(buffer, FORCED_NAME); #endif } break; @@ -605,7 +605,7 @@ BOOL GetDevices(DWORD devnum) uuprintf("Found non-USB non-removable device '%s' => Eliminated", buffer); continue; } - safe_strcpy(str, sizeof(str), "????:????"); // Couldn't figure VID:PID + static_strcpy(str, "????:????"); // Couldn't figure VID:PID } else { static_sprintf(str, "%04X:%04X", props.vid, props.pid); } @@ -731,14 +731,14 @@ BOOL GetDevices(DWORD devnum) } // We have multiple volumes assigned to the same device (multiple partitions) // If that is the case, use "Multiple Volumes" instead of the label - safe_strcpy(entry_msg, sizeof(entry_msg), (((drive_letters[0] != 0) && (drive_letters[1] != 0))? + static_strcpy(entry_msg, (((drive_letters[0] != 0) && (drive_letters[1] != 0))? lmprintf(MSG_047):label)); for (k=0, remove_drive=0; drive_letters[k] && (!remove_drive); k++) { // Append all the drive letters we detected letter_name[2] = drive_letters[k]; if (right_to_left_mode) - safe_strcat(entry_msg, sizeof(entry_msg), RIGHT_TO_LEFT_MARK); - safe_strcat(entry_msg, sizeof(entry_msg), letter_name); + static_strcat(entry_msg, RIGHT_TO_LEFT_MARK); + static_strcat(entry_msg, letter_name); if (drive_letters[k] == (PathGetDriveNumberU(app_dir) + 'A')) remove_drive = 1; if (drive_letters[k] == (PathGetDriveNumberU(system_dir) + 'A')) diff --git a/src/dos.c b/src/dos.c index 220a28ed..c73b17ce 100644 --- a/src/dos.c +++ b/src/dos.c @@ -301,8 +301,8 @@ static BOOL ExtractMSDOS(const char* path) return FALSE; // Reduce the visible mess by placing all the locale files into a subdir - safe_strcpy(locale_path, sizeof(locale_path), path); - safe_strcat(locale_path, sizeof(locale_path), "LOCALE\\"); + static_strcpy(locale_path, path); + static_strcat(locale_path, "LOCALE\\"); CreateDirectoryA(locale_path, NULL); len = GetSystemDirectoryA(dllname, sizeof(dllname)); @@ -310,7 +310,7 @@ static BOOL ExtractMSDOS(const char* path) uprintf("Unable to get system directory: %s\n", WindowsErrorString()); goto out; } - safe_strcat(dllname, sizeof(dllname), "\\diskcopy.dll"); + static_strcat(dllname, "\\diskcopy.dll"); hDLL = LoadLibraryA(dllname); if (hDLL == NULL) { uprintf("Unable to open %s: %s\n", dllname, WindowsErrorString()); @@ -375,15 +375,15 @@ BOOL ExtractFreeDOS(const char* path) } // Reduce the visible mess by placing all the locale files into a subdir - safe_strcpy(locale_path, sizeof(locale_path), path); - safe_strcat(locale_path, sizeof(locale_path), "LOCALE\\"); + static_strcpy(locale_path, path); + static_strcat(locale_path, "LOCALE\\"); CreateDirectoryA(locale_path, NULL); for (i=0; i= safe_strlen(config_path.String[i])) - safe_strcpy(img_report.cfg_path, sizeof(img_report.cfg_path), config_path.String[i]); + static_strcpy(img_report.cfg_path, config_path.String[i]); } uprintf(" Will use '%s' for Syslinux", img_report.cfg_path); // Extract all of the isolinux.bin files we found to identify their versions @@ -811,7 +811,7 @@ out: fclose(fd); sl_version = GetSyslinuxVersion(buf, size, &ext); if (img_report.sl_version == 0) { - safe_strcpy(img_report.sl_version_ext, sizeof(img_report.sl_version_ext), ext); + static_strcpy(img_report.sl_version_ext, ext); img_report.sl_version = sl_version; sl_index = i; } else if ((img_report.sl_version != sl_version) || (safe_strcmp(img_report.sl_version_ext, ext) != 0)) { @@ -822,7 +822,7 @@ out: // Where possible, prefer to the one that resides in the same directory as the config file. for (j=safe_strlen(img_report.cfg_path); (j>0) && (img_report.cfg_path[j]!='/'); j--); if (safe_strnicmp(img_report.cfg_path, isolinux_path.String[i], j) == 0) { - safe_strcpy(img_report.sl_version_ext, sizeof(img_report.sl_version_ext), ext); + static_strcpy(img_report.sl_version_ext, ext); img_report.sl_version = sl_version; sl_index = i; } @@ -855,7 +855,7 @@ out: // In case we have a WinPE 1.x based iso, we extract and parse txtsetup.sif // during scan, to see if /minint was provided for OsLoadOptions, as it decides // whether we should use 0x80 or 0x81 as the disk ID in the MBR - safe_sprintf(path, sizeof(path), "/%s/txtsetup.sif", + static_sprintf(path, "/%s/txtsetup.sif", basedir[((img_report.winpe&WINPE_I386) == WINPE_I386)?0:1]); ExtractISOFile(src_iso, path, tmp_sif, FILE_ATTRIBUTE_NORMAL); tmp = get_token_data_file("OsLoadOptions", tmp_sif); @@ -903,13 +903,13 @@ out: if (img_report.has_efi == 0x80) ExtractEfiImgFiles(dest_dir); if (HAS_SYSLINUX(img_report)) { - safe_sprintf(path, sizeof(path), "%s\\syslinux.cfg", dest_dir); + static_sprintf(path, "%s\\syslinux.cfg", dest_dir); // Create a /syslinux.cfg (if none exists) that points to the existing isolinux cfg fd = fopen(path, "r"); if (fd != NULL && img_report.needs_syslinux_overwrite) { fclose(fd); fd = NULL; - safe_sprintf(path2, sizeof(path2), "%s\\syslinux.org", dest_dir); + static_sprintf(path2, "%s\\syslinux.org", dest_dir); uprintf("Renaming: %s âž” %s", path, path2); IGNORE_RETVAL(rename(path, path2)); } @@ -1166,7 +1166,7 @@ BOOL ExtractEfiImgFiles(const char* dir) iso9660_readfat_private* p_private = NULL; libfat_sector_t s; int32_t dc, c; - struct libfat_filesystem *fs; + struct libfat_filesystem *fs = NULL; struct libfat_direntry direntry; char name[12] = { 0 }; char path[64]; @@ -1244,13 +1244,13 @@ BOOL ExtractEfiImgFiles(const char* dir) uprintf("Could not create directory '%s': %s\n", path, WindowsErrorString()); continue; } - safe_strcat(path, sizeof(path), "\\boot"); + static_strcat(path, "\\boot"); if (!CreateDirectoryA(path, 0) && (GetLastError() != ERROR_ALREADY_EXISTS)) { uprintf("Could not create directory '%s': %s\n", path, WindowsErrorString()); continue; } - safe_strcat(path, sizeof(path), "\\"); - safe_strcat(path, sizeof(path), efi_bootname[i]); + static_strcat(path, "\\"); + static_strcat(path, efi_bootname[i]); uprintf("Extracting: %s (from '%s', %s)", path, img_report.efi_img_path, SizeToHumanReadable(file_size, FALSE, FALSE)); handle = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, diff --git a/src/net.c b/src/net.c index 2e77d589..00d3e3ce 100644 --- a/src/net.c +++ b/src/net.c @@ -205,7 +205,7 @@ const char* WinInetErrorString(void) InternetGetLastResponseInfoA(&error_code, error_string, &size); return error_string; default: - safe_sprintf(error_string, sizeof(error_string), "Unknown internet error 0x%08lX", error_code); + static_sprintf(error_string, "Unknown internet error 0x%08lX", error_code); return error_string; } } @@ -275,7 +275,7 @@ DWORD DownloadFile(const char* url, const char* file, HWND hProgressDialog) uprintf("Network is unavailable: %s\n", WinInetErrorString()); goto out; } - safe_sprintf(agent, ARRAYSIZE(agent), APPLICATION_NAME "/%d.%d.%d (Windows NT %d.%d%s)", + static_sprintf(agent, APPLICATION_NAME "/%d.%d.%d (Windows NT %d.%d%s)", rufus_version[0], rufus_version[1], rufus_version[2], nWindowsVersion>>4, nWindowsVersion&0x0F, is_x64()?"; WOW64":""); hSession = InternetOpenA(agent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); @@ -467,7 +467,7 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param) goto out; hostname[sizeof(hostname)-1] = 0; - safe_sprintf(agent, ARRAYSIZE(agent), APPLICATION_NAME "/%d.%d.%d (Windows NT %d.%d%s)", + static_sprintf(agent, APPLICATION_NAME "/%d.%d.%d (Windows NT %d.%d%s)", rufus_version[0], rufus_version[1], rufus_version[2], nWindowsVersion >> 4, nWindowsVersion & 0x0F, is_x64() ? "; WOW64" : ""); hSession = InternetOpenA(agent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); @@ -493,7 +493,7 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param) // and then remove each each of the components until we find our match. For instance, we may first // look for rufus_win_x64_6.2.ver (Win8 x64) but only get a match for rufus_win_x64_6.ver (Vista x64 or later) // This allows sunsetting OS versions (eg XP) or providing different downloads for different archs/groups. - safe_sprintf(urlpath, sizeof(urlpath), "%s%s%s_%s_%lu.%lu.ver", APPLICATION_NAME, (k==0)?"":"_", + static_sprintf(urlpath, "%s%s%s_%s_%lu.%lu.ver", APPLICATION_NAME, (k==0)?"":"_", (k==0)?"":channel[k], archname[is_x64()?1:0], os_version.dwMajorVersion, os_version.dwMinorVersion); vuprintf("Base update check: %s\n", urlpath); for (i=0, j=(int)safe_strlen(urlpath)-5; (j>0)&&(i Just craft a default process name that includes the PID if (!bGotExePath) { - safe_sprintf(exe_path, MAX_PATH, "Unknown_Process_%" PRIu64, + static_sprintf(exe_path, "Unknown_Process_%" PRIu64, (ULONGLONG)handleInfo->UniqueProcessId); } } diff --git a/src/registry.h b/src/registry.h index 151ca751..81eb6803 100644 --- a/src/registry.h +++ b/src/registry.h @@ -89,12 +89,12 @@ static __inline BOOL _GetRegistryKey(HKEY key_root, const char* key_name, DWORD if (i + sizeof(software_prefix) >= sizeof(long_key_name)) return FALSE; strcpy(long_key_name, software_prefix); - safe_strcat(long_key_name, sizeof(long_key_name), key_name); + static_strcat(long_key_name, key_name); long_key_name[sizeof(software_prefix) + i - 1] = 0; } else { if (i >= sizeof(long_key_name)) return FALSE; - safe_strcpy(long_key_name, sizeof(long_key_name), key_name); + static_strcpy(long_key_name, key_name); long_key_name[i] = 0; } i++; @@ -164,12 +164,12 @@ static __inline BOOL _SetRegistryKey(HKEY key_root, const char* key_name, DWORD if (i + sizeof(software_prefix) >= sizeof(long_key_name)) goto out; strcpy(long_key_name, software_prefix); - safe_strcat(long_key_name, sizeof(long_key_name), key_name); + static_strcat(long_key_name, key_name); long_key_name[sizeof(software_prefix) + i - 1] = 0; } else { if (i >= sizeof(long_key_name)) goto out; - safe_strcpy(long_key_name, sizeof(long_key_name), key_name); + static_strcpy(long_key_name, key_name); long_key_name[i] = 0; } i++; diff --git a/src/rufus.c b/src/rufus.c index 844751c1..8219b41e 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -305,8 +305,8 @@ static BOOL DefineClusterSizes(void) tmp[0] = 0; // Tell the user if we're going to use Large FAT32 or regular if ((fs == FS_FAT32) && ((SelectedDrive.DiskSize > LARGE_FAT32_SIZE) || (force_large_fat32))) - safe_strcat(tmp, sizeof(tmp), "Large "); - safe_strcat(tmp, sizeof(tmp), FileSystemLabel[fs]); + static_strcat(tmp, "Large "); + static_strcat(tmp, FileSystemLabel[fs]); if (default_fs == FS_UNKNOWN) { entry = lmprintf(MSG_030, tmp); default_fs = fs; @@ -665,7 +665,7 @@ static BOOL PopulateProperties(int ComboIndex) EnableBootOptions(TRUE, TRUE); // Set a proposed label according to the size (eg: "256MB", "8GB") - safe_sprintf(SelectedDrive.proposed_label, sizeof(SelectedDrive.proposed_label), + static_sprintf(SelectedDrive.proposed_label, SizeToHumanReadable(SelectedDrive.DiskSize, FALSE, use_fake_units)); // Add a tooltip (with the size of the device in parenthesis) @@ -925,8 +925,7 @@ BOOL CALLBACK LogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) static void CALLBACK ClockTimer(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { timer++; - safe_sprintf(szTimer, sizeof(szTimer), "%02d:%02d:%02d", - timer/3600, (timer%3600)/60, timer%60); + static_sprintf(szTimer, "%02d:%02d:%02d", timer/3600, (timer%3600)/60, timer%60); SendMessageA(hStatus, SB_SETTEXTA, SBT_OWNERDRAW | SB_SECTION_RIGHT, (LPARAM)szTimer); } @@ -1402,7 +1401,7 @@ static BOOL BootCheck(void) if ((grub2_len == 0) && (DownloadStatus == 404)) { // Couldn't locate the file on the server => try to download without the version extra uprintf("Extended version was not found, trying main version..."); - safe_strcpy(tmp2, sizeof(tmp2), img_report.grub2_version); + static_strcpy(tmp2, img_report.grub2_version); // Isolate the #.### part for (i = 0; ((tmp2[i] >= '0') && (tmp2[i] <= '9')) || (tmp2[i] == '.'); i++); tmp2[i] = 0; @@ -1752,7 +1751,7 @@ static void InitDialog(HWND hDlg) } else { embedded_sl_version[i] = GetSyslinuxVersion(buf, len, &ext); static_sprintf(embedded_sl_version_str[i], "%d.%02d", SL_MAJOR(embedded_sl_version[i]), SL_MINOR(embedded_sl_version[i])); - safe_strcpy(embedded_sl_version_ext[i], sizeof(embedded_sl_version_ext[i]), ext); + static_strcpy(embedded_sl_version_ext[i], ext); free(buf); } } @@ -1972,7 +1971,7 @@ static void ShowLanguageMenu(RECT rcExclude) static_sprintf(lang, LEFT_TO_RIGHT_EMBEDDING "(%s) " POP_DIRECTIONAL_FORMATTING "%s", r, l); safe_free(str); } else { - safe_strcpy(lang, sizeof(lang), lcmd->txt[1]); + static_strcpy(lang, lcmd->txt[1]); } InsertMenuU(menu, -1, MF_BYPOSITION|((selected_locale == lcmd)?MF_CHECKED:0), UM_LANGUAGE_MENU_MAX++, lang); } @@ -2047,7 +2046,7 @@ static void SaveVHD(void) ULARGE_INTEGER free_space; if (DriveIndex >= 0) - safe_sprintf(filename, sizeof(filename), "%s.vhd", DriveLabel.String[DriveIndex]); + static_sprintf(filename, "%s.vhd", DriveLabel.String[DriveIndex]); if ((DriveIndex != CB_ERR) && (!format_op_in_progress) && (format_thid == NULL)) { img_save.Type = IMG_SAVE_TYPE_VHD; img_save.DeviceNum = (DWORD)ComboBox_GetItemData(hDeviceList, DriveIndex); @@ -2075,7 +2074,7 @@ static void SaveVHD(void) uprintf("\r\nSave to VHD operation started"); PrintInfo(0, -1); timer = 0; - safe_sprintf(szTimer, sizeof(szTimer), "00:00:00"); + static_sprintf(szTimer, "00:00:00"); SendMessageA(hStatus, SB_SETTEXTA, SBT_OWNERDRAW | SB_SECTION_RIGHT, (LPARAM)szTimer); SetTimer(hMainDialog, TID_APP_TIMER, 1000, ClockTimer); } else { @@ -2120,7 +2119,7 @@ static void SaveISO(void) (img_save.BufSize > 8 * MB) && (img_save.DeviceSize <= img_save.BufSize * 64); img_save.BufSize /= 2); if ((img_save.Label != NULL) && (img_save.Label[0] != 0)) - safe_sprintf(filename, sizeof(filename), "%s.iso", img_save.Label); + static_sprintf(filename, "%s.iso", img_save.Label); uprintf("ISO media size %s", SizeToHumanReadable(img_save.DeviceSize, FALSE, FALSE)); img_save.ImagePath = FileDialog(TRUE, NULL, &img_ext, 0); @@ -2141,7 +2140,7 @@ static void SaveISO(void) uprintf("\r\nSave to ISO operation started"); PrintInfo(0, -1); timer = 0; - safe_sprintf(szTimer, sizeof(szTimer), "00:00:00"); + static_sprintf(szTimer, "00:00:00"); SendMessageA(hStatus, SB_SETTEXTA, SBT_OWNERDRAW | SB_SECTION_RIGHT, (LPARAM)szTimer); SetTimer(hMainDialog, TID_APP_TIMER, 1000, ClockTimer); } else { @@ -2612,7 +2611,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA uprintf("\r\nFormat operation started"); PrintInfo(0, -1); timer = 0; - safe_sprintf(szTimer, sizeof(szTimer), "00:00:00"); + static_sprintf(szTimer, "00:00:00"); SendMessageA(hStatus, SB_SETTEXTA, SBT_OWNERDRAW | SB_SECTION_RIGHT, (LPARAM)szTimer); SetTimer(hMainDialog, TID_APP_TIMER, 1000, ClockTimer); } @@ -2645,7 +2644,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA if (format_thid != NULL) { PrintInfo(0, -1); timer = 0; - safe_sprintf(szTimer, sizeof(szTimer), "00:00:00"); + static_sprintf(szTimer, "00:00:00"); SendMessageA(hStatus, SB_SETTEXTA, SBT_OWNERDRAW | SB_SECTION_RIGHT, (LPARAM)szTimer); SetTimer(hMainDialog, TID_APP_TIMER, 1000, ClockTimer); } else { @@ -3116,24 +3115,24 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine } if (GetSystemDirectoryU(system_dir, sizeof(system_dir)) == 0) { uprintf("Could not get system directory: %s", WindowsErrorString()); - safe_strcpy(system_dir, sizeof(system_dir), "C:\\Windows\\System32"); + static_strcpy(system_dir, "C:\\Windows\\System32"); } if (GetTempPathU(sizeof(temp_dir), temp_dir) == 0) { uprintf("Could not get temp directory: %s", WindowsErrorString()); - safe_strcpy(temp_dir, sizeof(temp_dir), ".\\"); + static_strcpy(temp_dir, ".\\"); } // Construct Sysnative ourselves as there is no GetSysnativeDirectory() call // By default (64bit app running on 64 bit OS or 32 bit app running on 32 bit OS) // Sysnative and System32 are the same - safe_strcpy(sysnative_dir, sizeof(sysnative_dir), system_dir); + static_strcpy(sysnative_dir, system_dir); // But if the app is 32 bit and the OS is 64 bit, Sysnative must differ from System32 #if (!defined(_WIN64) && !defined(BUILD64)) if (is_x64()) { if (GetSystemWindowsDirectoryU(sysnative_dir, sizeof(sysnative_dir)) == 0) { uprintf("Could not get Windows directory: %s", WindowsErrorString()); - safe_strcpy(sysnative_dir, sizeof(sysnative_dir), "C:\\Windows"); + static_strcpy(sysnative_dir, "C:\\Windows"); } - safe_strcat(sysnative_dir, sizeof(sysnative_dir), "\\Sysnative"); + static_strcat(sysnative_dir, "\\Sysnative"); } #endif @@ -3181,7 +3180,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine loc_data = (BYTE*)GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_LC_RUFUS_LOC), _RT_RCDATA, "embedded.loc", &loc_size, FALSE); if ( (GetTempFileNameU(temp_dir, APPLICATION_NAME, 0, loc_file) == 0) || (loc_file[0] == 0) ) { // Last ditch effort to get a loc file - just extract it to the current directory - safe_strcpy(loc_file, sizeof(loc_file), rufus_loc); + static_strcpy(loc_file, rufus_loc); } hFile = CreateFileU(loc_file, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, @@ -3194,7 +3193,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine uprintf("localization: extracted data to '%s'", loc_file); safe_closehandle(hFile); } else { - safe_sprintf(loc_file, sizeof(loc_file), "%s\\%s", app_dir, rufus_loc); + static_sprintf(loc_file, "%s\\%s", app_dir, rufus_loc); external_loc_file = TRUE; uprintf("using external loc file '%s'", loc_file); } diff --git a/src/rufus.h b/src/rufus.h index d2cfa677..5d4bf008 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -95,8 +95,10 @@ #define safe_strcp(dst, dst_max, src, count) do {memcpy(dst, src, safe_min(count, dst_max)); \ ((char*)dst)[safe_min(count, dst_max)-1] = 0;} while(0) #define safe_strcpy(dst, dst_max, src) safe_strcp(dst, dst_max, src, safe_strlen(src)+1) +#define static_strcpy(dst, src) safe_strcpy(dst, sizeof(dst), src) #define safe_strncat(dst, dst_max, src, count) strncat(dst, src, safe_min(count, dst_max - safe_strlen(dst) - 1)) #define safe_strcat(dst, dst_max, src) safe_strncat(dst, dst_max, src, safe_strlen(src)+1) +#define static_strcat(dst, src) safe_strcat(dst, sizeof(dst), src) #define safe_strcmp(str1, str2) strcmp(((str1==NULL)?"":str1), ((str2==NULL)?"":str2)) #define safe_strstr(str1, str2) strstr(((str1==NULL)?"":str1), ((str2==NULL)?"":str2)) #define safe_stricmp(str1, str2) _stricmp(((str1==NULL)?"":str1), ((str2==NULL)?"":str2)) diff --git a/src/rufus.rc b/src/rufus.rc index 8389569c..15c14e25 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 242, 376 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 2.16.1174" +CAPTION "Rufus 2.17.1175" FONT 8, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 @@ -366,8 +366,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,16,1174,0 - PRODUCTVERSION 2,16,1174,0 + FILEVERSION 2,17,1175,0 + PRODUCTVERSION 2,17,1175,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -384,13 +384,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.16.1174" + VALUE "FileVersion", "2.17.1175" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2017 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "2.16.1174" + VALUE "ProductVersion", "2.17.1175" END END BLOCK "VarFileInfo" diff --git a/src/settings.h b/src/settings.h index 9b2a57c5..39364c87 100644 --- a/src/settings.h +++ b/src/settings.h @@ -94,7 +94,7 @@ static __inline char* ReadIniKeyStr(const char* key) { str[0] = 0; val = get_token_data_file(key, ini_file); if (val != NULL) { - safe_strcpy(str, sizeof(str), val); + static_strcpy(str, val); free(val); } return str; diff --git a/src/smart.c b/src/smart.c index 72b60149..7b32e328 100644 --- a/src/smart.c +++ b/src/smart.c @@ -68,7 +68,7 @@ const char* SptStrerr(int errcode) static char scsi_err[64]; if ((errcode > 0) && (errcode <= 0xff)) { - safe_sprintf(scsi_err, sizeof(scsi_err), "SCSI status: 0x%02X", (uint8_t)errcode); + static_sprintf(scsi_err, "SCSI status: 0x%02X", (uint8_t)errcode); return (const char*)scsi_err; } diff --git a/src/stdfn.c b/src/stdfn.c index 1874574a..90ef4b8c 100644 --- a/src/stdfn.c +++ b/src/stdfn.c @@ -235,7 +235,7 @@ void GetWindowsVersion(void) BOOL ws; nWindowsVersion = WINDOWS_UNDEFINED; - safe_strcpy(WindowsVersionStr, sizeof(WindowsVersionStr), "Windows Undefined"); + static_strcpy(WindowsVersionStr, "Windows Undefined"); memset(&vi, 0, sizeof(vi)); vi.dwOSVersionInfoSize = sizeof(vi); @@ -329,9 +329,9 @@ void GetWindowsVersion(void) GetRegistryKeyStr(REGKEY_HKLM, "Microsoft\\Windows NT\\CurrentVersion\\CurrentBuildNumber", build_number, sizeof(build_number)); if (build_number[0] != 0) { nWindowsBuildNumber = atoi(build_number); // Keep a global copy - safe_strcat(WindowsVersionStr, sizeof(WindowsVersionStr), " (Build "); - safe_strcat(WindowsVersionStr, sizeof(WindowsVersionStr), build_number); - safe_strcat(WindowsVersionStr, sizeof(WindowsVersionStr), ")"); + static_strcat(WindowsVersionStr, " (Build "); + static_strcat(WindowsVersionStr, build_number); + static_strcat(WindowsVersionStr, ")"); } } @@ -905,7 +905,7 @@ char* GetCurrentMUI(void) (pfLCIDToLocaleName(GetUserDefaultUILanguage(), wmui_str, LOCALE_NAME_MAX_LENGTH, 0) > 0) ) { wchar_to_utf8_no_alloc(wmui_str, mui_str, LOCALE_NAME_MAX_LENGTH); } else { - safe_strcpy(mui_str, LOCALE_NAME_MAX_LENGTH, "en-US"); + static_strcpy(mui_str, "en-US"); } return mui_str; } diff --git a/src/stdio.c b/src/stdio.c index c3975f36..c783554e 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -151,7 +151,7 @@ static char err_string[256] = {0}; error_code = GetLastError(); - safe_sprintf(err_string, sizeof(err_string), "[0x%08lX] ", error_code); + static_sprintf(err_string, "[0x%08lX] ", error_code); size = FormatMessageU(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, HRESULT_CODE(error_code), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &err_string[strlen(err_string)], @@ -159,10 +159,10 @@ static char err_string[256] = {0}; if (size == 0) { format_error = GetLastError(); if ((format_error) && (format_error != 0x13D)) // 0x13D, decode error, is returned for unknown codes - safe_sprintf(err_string, sizeof(err_string), - "Windows error code 0x%08lX (FormatMessage error code 0x%08lX)", error_code, format_error); + static_sprintf(err_string, "Windows error code 0x%08lX (FormatMessage error code 0x%08lX)", + error_code, format_error); else - safe_sprintf(err_string, sizeof(err_string), "Unknown error 0x%08lX", error_code); + static_sprintf(err_string, "Unknown error 0x%08lX", error_code); } SetLastError(error_code); // Make sure we don't change the errorcode on exit diff --git a/src/stdlg.c b/src/stdlg.c index d2524bbc..29eccaef 100644 --- a/src/stdlg.c +++ b/src/stdlg.c @@ -202,7 +202,7 @@ void BrowseForFolder(void) { if (tmp_path == NULL) { uprintf("Could not convert path\n"); } else { - safe_strcpy(szFolderPath, MAX_PATH, tmp_path); + static_strcpy(szFolderPath, tmp_path); safe_free(tmp_path); } } else { @@ -630,7 +630,7 @@ INT_PTR CALLBACK AboutCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP CenterDialog(hDlg); if (settings_commcheck) ShowWindow(GetDlgItem(hDlg, IDC_ABOUT_UPDATES), SW_SHOW); - safe_sprintf(about_blurb, sizeof(about_blurb), about_blurb_format, lmprintf(MSG_174|MSG_RTF), + static_sprintf(about_blurb, about_blurb_format, lmprintf(MSG_174|MSG_RTF), lmprintf(MSG_175|MSG_RTF, rufus_version[0], rufus_version[1], rufus_version[2]), right_to_left_mode?"Akeo \\\\ Pete Batard 2011-2017 © Copyright":"Copyright © 2011-2017 Pete Batard / Akeo", lmprintf(MSG_176|MSG_RTF), lmprintf(MSG_177|MSG_RTF), lmprintf(MSG_178|MSG_RTF)); @@ -1459,7 +1459,7 @@ INT_PTR CALLBACK UpdateCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM l IGNORE_RETVAL(ComboBox_SetCurSel(hBeta, ReadSettingBool(SETTING_INCLUDE_BETAS)?0:1)); hPolicy = GetDlgItem(hDlg, IDC_POLICY); SendMessage(hPolicy, EM_AUTOURLDETECT, 1, 0); - safe_sprintf(update_policy_text, sizeof(update_policy_text), update_policy, lmprintf(MSG_179|MSG_RTF), + static_sprintf(update_policy_text, update_policy, lmprintf(MSG_179|MSG_RTF), lmprintf(MSG_180|MSG_RTF), lmprintf(MSG_181|MSG_RTF), lmprintf(MSG_182|MSG_RTF), lmprintf(MSG_183|MSG_RTF), lmprintf(MSG_184|MSG_RTF), lmprintf(MSG_185|MSG_RTF), lmprintf(MSG_186|MSG_RTF)); SendMessageA(hPolicy, EM_SETTEXTEX, (WPARAM)&friggin_microsoft_unicode_amateurs, (LPARAM)update_policy_text); diff --git a/src/vhd.c b/src/vhd.c index c1972989..31042602 100644 --- a/src/vhd.c +++ b/src/vhd.c @@ -110,7 +110,7 @@ static BOOL Get7ZipPath(void) { if ( (GetRegistryKeyStr(REGKEY_HKCU, "7-Zip\\Path", sevenzip_path, sizeof(sevenzip_path))) || (GetRegistryKeyStr(REGKEY_HKLM, "7-Zip\\Path", sevenzip_path, sizeof(sevenzip_path))) ) { - safe_strcat(sevenzip_path, sizeof(sevenzip_path), "\\7z.exe"); + static_strcat(sevenzip_path, "\\7z.exe"); return (_access(sevenzip_path, 0) != -1); } return FALSE; @@ -471,11 +471,11 @@ BOOL WimExtractFile_7z(const char* image, int index, const char* src, const char // return an error code if it can't extract the file), we need // to issue 2 passes. See github issue #680. for (n = 0; n < 2; n++) { - safe_strcpy(tmpdst, sizeof(tmpdst), dst); + static_strcpy(tmpdst, dst); for (i = strlen(tmpdst) - 1; (i > 0) && (tmpdst[i] != '\\') && (tmpdst[i] != '/'); i--); tmpdst[i] = 0; - safe_sprintf(cmdline, sizeof(cmdline), "\"%s\" -y e \"%s\" %s%s", sevenzip_path, + static_sprintf(cmdline, "\"%s\" -y e \"%s\" %s%s", sevenzip_path, image, (n == 0) ? index_prefix : "", src); if (RunCommand(cmdline, tmpdst, FALSE) != 0) { uprintf(" Could not launch 7z.exe: %s", WindowsErrorString()); @@ -484,8 +484,8 @@ BOOL WimExtractFile_7z(const char* image, int index, const char* src, const char for (i = safe_strlen(src); (i > 0) && (src[i] != '\\') && (src[i] != '/'); i--); if (i == 0) - safe_strcat(tmpdst, sizeof(tmpdst), "\\"); - safe_strcat(tmpdst, sizeof(tmpdst), &src[i]); + static_strcat(tmpdst, "\\"); + static_strcat(tmpdst, &src[i]); if (_access(tmpdst, 0) == 0) // File was extracted => move on break;