summaryrefslogtreecommitdiff
path: root/pyuno
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2013-11-29 17:26:54 +0100
committerStephan Bergmann <sbergman@redhat.com>2013-12-04 16:45:33 +0100
commita8c7e6355542e5afee5975a093f5d5e0bc418e39 (patch)
tree1f927eff9b9b6a309161556d452e2230c567782d /pyuno
parent4c9ed76114ace311737dcda487894514ee0991fa (diff)
wsprintf is broken by design and never writes more than 1024 characters
Change-Id: I791e55bb5d98ee82c01271dcebafa7c4672cd424 (cherry picked from commit 50bd5c11f551f5274be9a4411c5ddcbd32bd9a03)
Diffstat (limited to 'pyuno')
-rw-r--r--pyuno/zipcore/python.cxx32
1 files changed, 17 insertions, 15 deletions
diff --git a/pyuno/zipcore/python.cxx b/pyuno/zipcore/python.cxx
index 9ef71839a1e2..517a6ae67845 100644
--- a/pyuno/zipcore/python.cxx
+++ b/pyuno/zipcore/python.cxx
@@ -192,10 +192,12 @@ int wmain(int argc, wchar_t ** argv, wchar_t **) {
exit(EXIT_FAILURE);
}
}
- wchar_t * value = new wchar_t[
- (urepathEnd - urepath) + MY_LENGTH(L";") + (pathEnd - path) +
- (n == 0 ? 0 : MY_LENGTH(L";") + (n - 1)) + 1]; //TODO: overflow
- wsprintfW(value, L"%s;%s%s%s", urepath, path, n == 0 ? L"" : L";", orig);
+ std::size_t len = (urepathEnd - urepath) + MY_LENGTH(L";") +
+ (pathEnd - path) + (n == 0 ? 0 : MY_LENGTH(L";") + (n - 1)) + 1;
+ //TODO: overflow
+ wchar_t * value = new wchar_t[len];
+ _snwprintf(
+ value, len, L"%s;%s%s%s", urepath, path, n == 0 ? L"" : L";", orig);
if (!SetEnvironmentVariableW(L"PATH", value)) {
exit(EXIT_FAILURE);
}
@@ -218,21 +220,21 @@ int wmain(int argc, wchar_t ** argv, wchar_t **) {
}
}
#ifdef __MINGW32__
- value = new wchar_t[
- (pathEnd - path) + MY_LENGTH(L";") + (pythonpath2End - pythonpath2) +
+ len = (pathEnd - path) + MY_LENGTH(L";") + (pythonpath2End - pythonpath2) +
MY_LENGTH(L";") + (pythonpath4End - pythonpath4) +
MY_LENGTH(L";") + (pythonpath3End - pythonpath3) +
- (n == 0 ? 0 : MY_LENGTH(L";") + (n - 1)) + 1]; //TODO: overflow
- wsprintfW(
- value, L"%s;%s;%s;%s%s%s", path, pythonpath2, pythonpath4, pythonpath3,
- n == 0 ? L"" : L";", orig);
+ (n == 0 ? 0 : MY_LENGTH(L";") + (n - 1)) + 1; //TODO: overflow
+ value = new wchar_t[len];
+ _snwprintf(
+ value, len, L"%s;%s;%s;%s%s%s", path, pythonpath2, pythonpath4,
+ pythonpath3, n == 0 ? L"" : L";", orig);
#else
- value = new wchar_t[
- (pathEnd - path) + MY_LENGTH(L";") + (pythonpath2End - pythonpath2) +
+ len = (pathEnd - path) + MY_LENGTH(L";") + (pythonpath2End - pythonpath2) +
MY_LENGTH(L";") + (pythonpath3End - pythonpath3) +
- (n == 0 ? 0 : MY_LENGTH(L";") + (n - 1)) + 1]; //TODO: overflow
- wsprintfW(
- value, L"%s;%s;%s%s%s", path, pythonpath2, pythonpath3,
+ (n == 0 ? 0 : MY_LENGTH(L";") + (n - 1)) + 1; //TODO: overflow
+ value = new wchar_t[len];
+ _snwprintf(
+ value, len, L"%s;%s;%s%s%s", path, pythonpath2, pythonpath3,
n == 0 ? L"" : L";", orig);
#endif
if (!SetEnvironmentVariableW(L"PYTHONPATH", value)) {