From 5d374bdc2cf3b38f9be60b30ee8fc98ea4c4e381 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Mon, 18 Dec 2023 17:11:54 -0600 Subject: [PATCH] lsteamclient: Use GetEnvironmentVariableW() in load_steamclient(). CW-Bug-Id: #23142 --- lsteamclient/steamclient_main.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lsteamclient/steamclient_main.c b/lsteamclient/steamclient_main.c index b2d0626cd..8aa58288d 100644 --- a/lsteamclient/steamclient_main.c +++ b/lsteamclient/steamclient_main.c @@ -304,18 +304,31 @@ struct w_steam_iface *create_win_interface(const char *name, void *u_iface) return ret; } +static BOOL get_env_win(const WCHAR *name, char *value, unsigned int size) +{ + DWORD i, env_size; + + if (!(env_size = GetEnvironmentVariableW(name, (WCHAR *)value, size / sizeof(WCHAR))) || env_size >= size / sizeof(WCHAR)) + return FALSE; + + for (i = 0; i <= env_size; ++i) + value[i] = ((WCHAR *)value)[i]; + + return TRUE; +} + static int load_steamclient(void) { char steam_app_id[4096], ignore_child_processes[4096]; struct steamclient_init_params params = {.g_tmppath = temp_path_buffer}; - if (!GetEnvironmentVariableA("SteamAppId", steam_app_id, ARRAY_SIZE(steam_app_id))) - params.steam_app_id_unset = GetLastError() == ERROR_ENVVAR_NOT_FOUND; + if (!get_env_win(u"SteamAppId", steam_app_id, sizeof(steam_app_id))) + params.steam_app_id_unset = TRUE; else params.steam_app_id = steam_app_id; - if (!GetEnvironmentVariableA("IgnoreChildProcesses", ignore_child_processes, ARRAY_SIZE(ignore_child_processes))) - params.ignore_child_processes_unset = GetLastError() == ERROR_ENVVAR_NOT_FOUND; + if (!get_env_win(u"IgnoreChildProcesses", ignore_child_processes, sizeof(ignore_child_processes))) + params.ignore_child_processes_unset = TRUE; else params.ignore_child_processes = ignore_child_processes;