From d22106276947ac05a0fae1d1e037c948d80fe627 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 16 May 2023 19:11:16 +0900 Subject: [PATCH] w32: Also use _putenv_s for gnupg_unsetenv. * common/sysutils.c (gnupg_setenv): Only enable use of _putenv_s with Security Feature in the CRT. (gnupg_unsetenv): Use _putenv_s when available. -- Signed-off-by: NIIBE Yutaka --- common/sysutils.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/common/sysutils.c b/common/sysutils.c index 0c2831541..ff75b698e 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -1148,7 +1148,7 @@ gnupg_setenv (const char *name, const char *value, int overwrite) return setenv (name, value, overwrite); #else /*!HAVE_SETENV*/ if (! getenv (name) || overwrite) -#ifdef HAVE_W32_SYSTEM +#if defined(HAVE_W32_SYSTEM) && defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES) { int e = _putenv_s (name, value); @@ -1203,6 +1203,18 @@ gnupg_unsetenv (const char *name) #ifdef HAVE_UNSETENV return unsetenv (name); +#elif defined(HAVE_W32_SYSTEM) && defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES) + { + int e = _putenv_s (name, ""); + + if (e) + { + gpg_err_set_errno (e); + return -1; + } + else + return 0; + } #else /*!HAVE_UNSETENV*/ { char *buf;