From 9423f015f157a95205543d4185f34eb73ebdb9e1 Mon Sep 17 00:00:00 2001 From: Maxim Krikun Date: Sat, 6 Feb 2021 19:38:35 +0300 Subject: [PATCH 1/2] fix PyWinObject_FromEnvironmentBlock behaviour --- win32/src/win32profilemodule.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/win32/src/win32profilemodule.cpp b/win32/src/win32profilemodule.cpp index 13b9b6f36..188efd917 100644 --- a/win32/src/win32profilemodule.cpp +++ b/win32/src/win32profilemodule.cpp @@ -50,11 +50,13 @@ PyObject *PyWinObject_FromEnvironmentBlock(WCHAR *multistring) return NULL; totallen = wcslen(multistring); while (totallen) { - /* Use *last* equal sign as separator, since per-drive working dirs are stored in the environment in the form - "=C:=C:\\somedir","=D:=D:\\someotherdir". These are retrievable by win32api.GetEnvironmentVariable('=C:'), - but don't appear in os.environ and are apparently undocumented + /* Official docs say that the name of an environment variable cannot include an equal sign. + Actually, there are names started with an equal sign, e.g. per-drive working dirs are stored in the form + "=C:=C:\\somedir", "=D:=D:\\someotherdir". These are retrievable by win32api.GetEnvironmentVariable('=C:'), + but don't appear in os.environ. Environment variable's value may contain an equal sign. + So we use the first equal sign from which the string is not started */ - eq = wcsrchr(multistring, '='); + eq = wcschr(multistring + 1, '='); if (eq == NULL) { // Use blank string for value if no equal sign present. ???? Maybe throw an error instead ???? vallen = 0; From d2d893c05d0f9b56c8ee772f836383ff36b9e08b Mon Sep 17 00:00:00 2001 From: Maxim Krikun Date: Sun, 7 Feb 2021 14:33:51 +0300 Subject: [PATCH 2/2] fix doc --- win32/src/win32profilemodule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32/src/win32profilemodule.cpp b/win32/src/win32profilemodule.cpp index 188efd917..17299f00b 100644 --- a/win32/src/win32profilemodule.cpp +++ b/win32/src/win32profilemodule.cpp @@ -54,7 +54,7 @@ PyObject *PyWinObject_FromEnvironmentBlock(WCHAR *multistring) Actually, there are names started with an equal sign, e.g. per-drive working dirs are stored in the form "=C:=C:\\somedir", "=D:=D:\\someotherdir". These are retrievable by win32api.GetEnvironmentVariable('=C:'), but don't appear in os.environ. Environment variable's value may contain an equal sign. - So we use the first equal sign from which the string is not started + So we use the first equal sign from which the string is not started as a separator */ eq = wcschr(multistring + 1, '='); if (eq == NULL) {