Repository: microsoft/terminal (language: cpp)

Issue:
Crash: access violation in WM_SETTINGCHANGE with lParam == 0
### Windows Terminal version

developer build

### Windows build number

10.0.22621.963

### Other Software

N/A

### Steps to reproduce

Using the "Switch User" feature of Windows and ran into an issue with a `WM_SETTINGCHANGE` getting fired at `IslandWindow.cpp` with `wParam == 0` and `lParam == 0`.  This in turn crashes while constructing the string on this line:

```cpp
const std::wstring param{ (wchar_t*)lparam };
```

https://github.com/microsoft/terminal/blob/21a62c5fefa36c619bd15bc80d43f54b4d878a5d/src/cascadia/WindowsTerminal/IslandWindow.cpp#L661-L677

The docs also suggest that NULL is a valid parameter for lParam.

https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange

> lParam
> 
> When the system sends this message as a result of a [SystemParametersInfo](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa) call, lParam is a pointer to a string that indicates the area containing the system parameter that was changed. This parameter does not usually indicate which specific system parameter changed. (Note that some applications send this message with lParam set to NULL.) In general, when you receive this message, you should check and reload any system parameter settings that are used by your application.

### Expected Behavior

No crash.

### Actual Behavior

crash due to access violation (nullptr)
Crash: access violation in WM_SETTINGCHANGE with lParam == 0
### Windows Terminal version

developer build

### Windows build number

10.0.22621.963

### Other Software

N/A

### Steps to reproduce

Using the "Switch User" feature of Windows and ran into an issue with a `WM_SETTINGCHANGE` getting fired at `IslandWindow.cpp` with `wParam == 0` and `lParam == 0`.  This in turn crashes while constructing the string on this line:

```cpp
const std::wstring param{ (wchar_t*)lparam };
```

https://github.com/microsoft/terminal/blob/21a62c5fefa36c619bd15bc80d43f54b4d878a5d/src/cascadia/WindowsTerminal/IslandWindow.cpp#L661-L677

The docs also suggest that NULL is a valid parameter for lParam.

https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange

> lParam
> 
> When the system sends this message as a result of a [SystemParametersInfo](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa) call, lParam is a pointer to a string that indicates the area containing the system parameter that was changed. This parameter does not usually indicate which specific system parameter changed. (Note that some applications send this message with lParam set to NULL.) In general, when you receive this message, you should check and reload any system parameter settings that are used by your application.

### Expected Behavior

No crash.

### Actual Behavior

crash due to access violation (nullptr)


Discussion / hints:

Fix patch:
diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp
index 4ed300f9be1..4ebe1c1bf34 100644
--- a/src/cascadia/WindowsTerminal/IslandWindow.cpp
+++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp
@@ -663,7 +663,7 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize
         // Currently, we only support checking when the OS theme changes. In
         // that case, wParam is 0. Re-evaluate when we decide to reload env vars
         // (GH#1125)
-        if (wparam == 0)
+        if (wparam == 0 && lparam != 0)
         {
             const std::wstring param{ (wchar_t*)lparam };
             // ImmersiveColorSet seems to be the notification that the OS theme


Test patch: