From 07e9db881c109ad060611f974e2d92402ca593af Mon Sep 17 00:00:00 2001 From: Andrew Tonner Date: Wed, 12 Feb 2020 16:13:26 -0800 Subject: [PATCH 1/4] failsafe for localtime(-1) on Windows to avoid segfault --- BasiliskII/src/macos_util.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BasiliskII/src/macos_util.cpp b/BasiliskII/src/macos_util.cpp index dea66451..ba7ac874 100644 --- a/BasiliskII/src/macos_util.cpp +++ b/BasiliskII/src/macos_util.cpp @@ -133,6 +133,13 @@ uint32 TimeToMacTime(time_t t) // This code is taken from glibc 2.2 // Convert to number of seconds elapsed since 1-Jan-1904 + + #ifdef WIN32 + if (t == -1) { + // failsafe as this will segfault + return 0; + } + #endif struct tm *local = localtime(&t); const int TM_EPOCH_YEAR = 1900; const int MAC_EPOCH_YEAR = 1904; From 837c82d8b893804dc5242ecc378c6a228f883d03 Mon Sep 17 00:00:00 2001 From: Andrew Tonner Date: Wed, 12 Feb 2020 16:16:31 -0800 Subject: [PATCH 2/4] expect TCHAR returns from RegQueryValueEx now that we are potentially building with _UNICODE --- .../src/Windows/user_strings_windows.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/BasiliskII/src/Windows/user_strings_windows.cpp b/BasiliskII/src/Windows/user_strings_windows.cpp index 0d98d61f..dc2993da 100755 --- a/BasiliskII/src/Windows/user_strings_windows.cpp +++ b/BasiliskII/src/Windows/user_strings_windows.cpp @@ -20,7 +20,7 @@ #include "sysdeps.h" #include "user_strings.h" - +#include "util_windows.h" // Platform-specific string definitions user_string_def platform_strings[] = { @@ -81,7 +81,11 @@ static const char *get_volume_name(void) HKEY hHelpKey; DWORD key_type, cbData; - static char volume[256]; + #ifdef _UNICODE + static char out_volume[256]; + #endif + + static TCHAR volume[256]; memset(volume, 0, sizeof(volume)); // Try Windows 2000 key first @@ -118,14 +122,20 @@ static const char *get_volume_name(void) } // Fix the error that some "tweak" apps do. - if (_stricmp(volume, "%USERNAME% on %COMPUTER%") == 0) - volume[0] = '\0'; + if (_tcsicmp(volume, TEXT("%USERNAME% on %COMPUTER%")) == 0) + volume[0] = TEXT('\0'); // No volume name found, default to "My Computer" if (volume[0] == 0) - strcpy(volume, "My Computer"); + _tcscpy(volume, TEXT("My Computer")); + + #ifdef _UNICODE + strlcpy(out_volume, volume, 256); + return out_volume; + #else return volume; + #endif } From 8b44b00da3449164e9a5409ae45223ec989253b7 Mon Sep 17 00:00:00 2001 From: Andrew Tonner Date: Wed, 12 Feb 2020 16:28:00 -0800 Subject: [PATCH 3/4] In extfs icon creation, ensure that the times on the host file are set correctly; actually allocate space for the other HInfo that set_finfo reads, such as the times --- BasiliskII/src/Windows/posix_emu.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/BasiliskII/src/Windows/posix_emu.cpp b/BasiliskII/src/Windows/posix_emu.cpp index 8d671abc..c93b2e09 100755 --- a/BasiliskII/src/Windows/posix_emu.cpp +++ b/BasiliskII/src/Windows/posix_emu.cpp @@ -392,14 +392,23 @@ void init_posix_emu(void) int fd = my_creat( custom_icon_name, 0 ); if(fd >= 0) { my_close(fd); + struct my_stat custom_icon_stat; + int stat_result = my_stat( custom_icon_name, &custom_icon_stat ); fd = open_rfork( custom_icon_name, O_RDWR|O_CREAT ); if(fd >= 0) { my_write( fd, my_comp_icon, sizeof(my_comp_icon) ); my_close(fd); - static uint8 host_finfo[SIZEOF_FInfo]; + // need room for the things from around the finfo that set_finfo reads + static uint8 custom_icon_hfile[ioFlXFndrInfo + SIZEOF_FXInfo]; + memset(custom_icon_hfile, 0, ioFlXFndrInfo + SIZEOF_FXInfo); + static uint8 * host_finfo = custom_icon_hfile + ioFlFndrInfo; uint32 finfo = Host2MacAddr(host_finfo); get_finfo(custom_icon_name, finfo, 0, false); WriteMacInt16(finfo + fdFlags, kIsInvisible); + if (stat_result == 0) { + WriteMacInt32(finfo - ioFlFndrInfo + ioFlCrDat, TimeToMacTime(custom_icon_stat.st_ctime)); + WriteMacInt32(finfo - ioFlFndrInfo + ioFlMdDat, TimeToMacTime(custom_icon_stat.st_mtime)); + } set_finfo(custom_icon_name, finfo, 0, false); get_finfo(my_computer, finfo, 0, true); WriteMacInt16(finfo + fdFlags, ReadMacInt16(finfo + fdFlags) | kHasCustomIcon); From 831e7a2268d16d1fd132d6c864e72d6e41edbec9 Mon Sep 17 00:00:00 2001 From: Andrew Tonner Date: Wed, 12 Feb 2020 21:29:44 -0800 Subject: [PATCH 4/4] Merge fixes to SheepShaver --- .../src/Windows/user_strings_windows.cpp | 19 ++++++++++++++----- SheepShaver/src/macos_util.cpp | 4 ++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/SheepShaver/src/Windows/user_strings_windows.cpp b/SheepShaver/src/Windows/user_strings_windows.cpp index 32e52d25..eb12de57 100755 --- a/SheepShaver/src/Windows/user_strings_windows.cpp +++ b/SheepShaver/src/Windows/user_strings_windows.cpp @@ -20,7 +20,7 @@ #include "sysdeps.h" #include "user_strings.h" - +#include "util_windows.h" // Platform-specific string definitions user_string_def platform_strings[] = { @@ -86,7 +86,11 @@ static const char *get_volume_name(void) HKEY hHelpKey; DWORD key_type, cbData; - static char volume[256]; + #ifdef _UNICODE + static char out_volume[256]; + #endif + + static TCHAR volume[256]; memset(volume, 0, sizeof(volume)); // Try Windows 2000 key first @@ -123,14 +127,19 @@ static const char *get_volume_name(void) } // Fix the error that some "tweak" apps do. - if (stricmp(volume, "%USERNAME% on %COMPUTER%") == 0) - volume[0] = '\0'; + if (_tcsicmp(volume, TEXT("%USERNAME% on %COMPUTER%")) == 0) + volume[0] = TEXT('\0'); // No volume name found, default to "My Computer" if (volume[0] == 0) - strcpy(volume, "My Computer"); + _tcscpy(volume, TEXT("My Computer")); + #ifdef _UNICODE + strlcpy(out_volume, volume, 256); + return out_volume; + #else return volume; + #endif } diff --git a/SheepShaver/src/macos_util.cpp b/SheepShaver/src/macos_util.cpp index 87eabb3d..6a3f9644 100644 --- a/SheepShaver/src/macos_util.cpp +++ b/SheepShaver/src/macos_util.cpp @@ -327,6 +327,10 @@ uint32 TimeToMacTime(time_t t) // Convert to number of seconds elapsed since 1-Jan-1904 #ifdef WIN32 + if (t == -1) { + // failsafe as this will segfault + return 0; + } struct tm *local = localtime(&t); #else struct tm result;