[net] fix incorrect architectures when querying for updates

This commit is contained in:
Pete Batard 2023-04-16 19:47:54 +01:00
parent f27dda1164
commit 6280e8020a
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
5 changed files with 33 additions and 39 deletions

View File

@ -625,17 +625,16 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
int status = 0; int status = 0;
const char* server_url = RUFUS_URL "/"; const char* server_url = RUFUS_URL "/";
int i, j, k, max_channel, verbose = 0, verpos[4]; int i, j, k, max_channel, verbose = 0, verpos[4];
static const char* archname[] = {"win_x86", "win_x64", "win_arm", "win_arm64", "win_none"}; static const char* channel[] = { "release", "beta", "test" }; // release channel
static const char* channel[] = {"release", "beta", "test"}; // release channel const char* accept_types[] = { "*/*\0", NULL };
const char* accept_types[] = {"*/*\0", NULL};
char* buf = NULL; char* buf = NULL;
char agent[64], hostname[64], urlpath[128], sigpath[256]; char agent[64], hostname[64], urlpath[128], sigpath[256];
DWORD dwSize, dwDownloaded, dwTotalSize, dwStatus; DWORD dwSize, dwDownloaded, dwTotalSize, dwStatus;
BYTE *sig = NULL; BYTE *sig = NULL;
OSVERSIONINFOA os_version = {sizeof(OSVERSIONINFOA), 0, 0, 0, 0, ""}; OSVERSIONINFOA os_version = { sizeof(OSVERSIONINFOA), 0, 0, 0, 0, "" };
HINTERNET hSession = NULL, hConnection = NULL, hRequest = NULL; HINTERNET hSession = NULL, hConnection = NULL, hRequest = NULL;
URL_COMPONENTSA UrlParts = {sizeof(URL_COMPONENTSA), NULL, 1, (INTERNET_SCHEME)0, URL_COMPONENTSA UrlParts = { sizeof(URL_COMPONENTSA), NULL, 1, (INTERNET_SCHEME)0,
hostname, sizeof(hostname), 0, NULL, 1, urlpath, sizeof(urlpath), NULL, 1}; hostname, sizeof(hostname), 0, NULL, 1, urlpath, sizeof(urlpath), NULL, 1 };
SYSTEMTIME ServerTime, LocalTime; SYSTEMTIME ServerTime, LocalTime;
FILETIME FileTime; FILETIME FileTime;
int64_t local_time = 0, reg_time, server_time, update_interval; int64_t local_time = 0, reg_time, server_time, update_interval;
@ -734,10 +733,10 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
// and then remove each of the <os_> components until we find our match. For instance, we may first // and then remove each of the <os_> 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) // 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. // This allows sunsetting OS versions (eg XP) or providing different downloads for different archs/groups.
static_sprintf(urlpath, "%s%s%s_%s_%lu.%lu.ver", APPLICATION_NAME, (k==0)?"":"_", static_sprintf(urlpath, "%s%s%s_win_%s_%lu.%lu.ver", APPLICATION_NAME, (k == 0) ? "": "_",
(k==0)?"":channel[k], archname[GetCpuArch()], os_version.dwMajorVersion, os_version.dwMinorVersion); (k == 0) ? "" : channel[k], GetAppArchName(), os_version.dwMajorVersion, os_version.dwMinorVersion);
vuprintf("Base update check: %s", urlpath); vuprintf("Base update check: %s", urlpath);
for (i=0, j=(int)safe_strlen(urlpath)-5; (j>0)&&(i<ARRAYSIZE(verpos)); j--) { for (i = 0, j = (int)safe_strlen(urlpath) - 5; (j > 0) && (i < ARRAYSIZE(verpos)); j--) {
if ((urlpath[j] == '.') || (urlpath[j] == '_')) { if ((urlpath[j] == '.') || (urlpath[j] == '_')) {
verpos[i++] = j; verpos[i++] = j;
} }

View File

@ -1,7 +1,7 @@
/* /*
* Rufus: The Reliable USB Formatting Utility * Rufus: The Reliable USB Formatting Utility
* Elementary Unicode compliant find/replace parser * Elementary Unicode compliant find/replace parser
* Copyright © 2012-2022 Pete Batard <pete@akeo.ie> * Copyright © 2012-2023 Pete Batard <pete@akeo.ie>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -914,14 +914,13 @@ void parse_update(char* buf, size_t len)
char allowed_rtf_chars[] = "abcdefghijklmnopqrstuvwxyz|~-_:*'"; char allowed_rtf_chars[] = "abcdefghijklmnopqrstuvwxyz|~-_:*'";
char allowed_std_chars[] = "\r\n ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"$%^&+=<>(){}[].,;#@/?"; char allowed_std_chars[] = "\r\n ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"$%^&+=<>(){}[].,;#@/?";
char download_url_name[24]; char download_url_name[24];
char *arch_names[5] = { "unknown", "x86", "x64", "arm", "arm64" };
// strchr includes the NUL terminator in the search, so take care of backslash before NUL // strchr includes the NUL terminator in the search, so take care of backslash before NUL
if ((buf == NULL) || (len < 2) || (len > 64 * KB) || (buf[len-1] != 0) || (buf[len-2] == '\\')) if ((buf == NULL) || (len < 2) || (len > 64 * KB) || (buf[len-1] != 0) || (buf[len-2] == '\\'))
return; return;
// Sanitize the data - Not a silver bullet, but it helps // Sanitize the data - Not a silver bullet, but it helps
len = safe_strlen(buf)+1; // Someone may be inserting NULs len = safe_strlen(buf)+1; // Someone may be inserting NULs
for (i=0; i<len-1; i++) { for (i = 0; i < len - 1; i++) {
// Check for valid RTF sequences as well as allowed chars if not RTF // Check for valid RTF sequences as well as allowed chars if not RTF
if (buf[i] == '\\') { if (buf[i] == '\\') {
// NB: we have a zero terminator, so we can afford a +1 without overflow // NB: we have a zero terminator, so we can afford a +1 without overflow
@ -933,25 +932,25 @@ void parse_update(char* buf, size_t len)
} }
} }
for (i=0; i<3; i++) for (i = 0; i < 3; i++)
update.version[i] = 0; update.version[i] = 0;
update.platform_min[0] = 5; update.platform_min[0] = 5;
update.platform_min[1] = 2; // XP or later update.platform_min[1] = 2; // XP or later
safe_free(update.download_url); safe_free(update.download_url);
safe_free(update.release_notes); safe_free(update.release_notes);
if ((data = get_sanitized_token_data_buffer("version", 1, buf, len)) != NULL) { if ((data = get_sanitized_token_data_buffer("version", 1, buf, len)) != NULL) {
for (i=0; (i<3) && ((token = strtok((i==0)?data:NULL, ".")) != NULL); i++) { for (i = 0; (i < 3) && ((token = strtok((i == 0) ? data : NULL, ".")) != NULL); i++) {
update.version[i] = (uint16_t)atoi(token); update.version[i] = (uint16_t)atoi(token);
} }
safe_free(data); safe_free(data);
} }
if ((data = get_sanitized_token_data_buffer("platform_min", 1, buf, len)) != NULL) { if ((data = get_sanitized_token_data_buffer("platform_min", 1, buf, len)) != NULL) {
for (i=0; (i<2) && ((token = strtok((i==0)?data:NULL, ".")) != NULL); i++) { for (i = 0; (i < 2) && ((token = strtok((i == 0) ? data : NULL, ".")) != NULL); i++) {
update.platform_min[i] = (uint32_t)atoi(token); update.platform_min[i] = (uint32_t)atoi(token);
} }
safe_free(data); safe_free(data);
} }
static_sprintf(download_url_name, "download_url_%s", arch_names[GetCpuArch()]); static_sprintf(download_url_name, "download_url_%s", GetAppArchName());
update.download_url = get_sanitized_token_data_buffer(download_url_name, 1, buf, len); update.download_url = get_sanitized_token_data_buffer(download_url_name, 1, buf, len);
if (update.download_url == NULL) if (update.download_url == NULL)
update.download_url = get_sanitized_token_data_buffer("download_url", 1, buf, len); update.download_url = get_sanitized_token_data_buffer("download_url", 1, buf, len);

View File

@ -557,8 +557,8 @@ extern char app_data_dir[MAX_PATH], *image_path, *fido_url;
*/ */
extern void GetWindowsVersion(void); extern void GetWindowsVersion(void);
extern BOOL is_x64(void); extern BOOL is_x64(void);
extern int GetCpuArch(void); extern const char* GetAppArchName(void);
extern const char *WindowsErrorString(void); extern const char* WindowsErrorString(void);
extern void DumpBufferHex(void *buf, size_t size); extern void DumpBufferHex(void *buf, size_t size);
extern void PrintStatusInfo(BOOL info, BOOL debug, unsigned int duration, int msg_id, ...); extern void PrintStatusInfo(BOOL info, BOOL debug, unsigned int duration, int msg_id, ...);
#define PrintStatus(...) PrintStatusInfo(FALSE, FALSE, __VA_ARGS__) #define PrintStatus(...) PrintStatusInfo(FALSE, FALSE, __VA_ARGS__)

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 3.23.2019" CAPTION "Rufus 3.23.2020"
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
@ -392,8 +392,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,23,2019,0 FILEVERSION 3,23,2020,0
PRODUCTVERSION 3,23,2019,0 PRODUCTVERSION 3,23,2020,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -411,13 +411,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", "3.23.2019" VALUE "FileVersion", "3.23.2020"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2023 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2023 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-3.23.exe" VALUE "OriginalFilename", "rufus-3.23.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.23.2019" VALUE "ProductVersion", "3.23.2020"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -223,22 +223,18 @@ BOOL is_x64(void)
return ret; return ret;
} }
int GetCpuArch(void) const char* GetAppArchName(void) {
{ #if defined(_M_AMD64)
SYSTEM_INFO info = { 0 }; return "x64";
GetNativeSystemInfo(&info); #elif defined(_M_IX86)
switch (info.wProcessorArchitecture) { return "x86";
case PROCESSOR_ARCHITECTURE_AMD64: #elif defined(_M_ARM64)
return ARCH_X86_64; return "arm64";
case PROCESSOR_ARCHITECTURE_INTEL: #elif defined(_M_ARM)
return ARCH_X86_64; return "arm";
case PROCESSOR_ARCHITECTURE_ARM64: #else
return ARCH_ARM_64; return "unknown";
case PROCESSOR_ARCHITECTURE_ARM: #endif
return ARCH_ARM_32;
default:
return ARCH_UNKNOWN;
}
} }
static const char* GetEdition(DWORD ProductType) static const char* GetEdition(DWORD ProductType)