diff options
author | Niraj Modi | 2017-03-14 07:17:16 +0000 |
---|---|---|
committer | Niraj Modi | 2017-03-14 07:17:16 +0000 |
commit | 3925ddf8add89cb600c9e5a6faff0cd669f3dc22 (patch) | |
tree | 70cf0bb578dc394c0c9a5e87d41867f19935d5ea | |
parent | 944b2802fde51aaa1691b593d3f55152b8c64b91 (diff) | |
download | eclipse.platform.swt-3925ddf8add89cb600c9e5a6faff0cd669f3dc22.tar.gz eclipse.platform.swt-3925ddf8add89cb600c9e5a6faff0cd669f3dc22.tar.xz eclipse.platform.swt-3925ddf8add89cb600c9e5a6faff0cd669f3dc22.zip |
Bug 157010 - [Win32] VM Crashes after changing file associations
Change-Id: I1caf940b9e047efb5ce379f986961be18629f349
Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java index f48a06d51e..e8b938f228 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -90,7 +90,21 @@ public static Program findProgram (String extension) { int [] lpcbData = new int [1]; int result = OS.RegQueryValueEx (phkResult [0], null, 0, null, (TCHAR) null, lpcbData); if (result == 0) { - TCHAR lpData = new TCHAR (0, lpcbData [0] / TCHAR.sizeof); + int length = lpcbData [0] / TCHAR.sizeof; + /* + * Crash is seen when the size of REG_SZ entry in HKEY_CLASSES_ROOT + * is not multiple of a Unicode byte length. The REG_SZ entry in + * Windows registry may not have been stored with the proper + * terminating null characters: e.g. non null terminated string or a + * single byte null terminated. Refer below MSDN article on this: + * https://msdn.microsoft.com/en-us/library/windows/desktop/ms724884 + * %28v=vs.85%29.aspx Hence solution is to adjust the buffer length + * accordingly. Refer Bug 157010 for more details. + */ + if (lpcbData [0] % TCHAR.sizeof != 0) { + length++; + } + TCHAR lpData = new TCHAR (0, length); result = OS.RegQueryValueEx (phkResult [0], null, 0, null, lpData, lpcbData); if (result == 0) program = getProgram (lpData.toString (0, lpData.strlen ()), extension); } @@ -161,6 +175,19 @@ static String getKeyValue (String string, boolean expand) { if (OS.RegQueryValueEx (phkResult [0], (TCHAR) null, 0, null, (TCHAR) null, lpcbData) == 0) { result = ""; int length = lpcbData [0] / TCHAR.sizeof; + /* + * Crash is seen when the size of REG_SZ entry in HKEY_CLASSES_ROOT + * is not multiple of a Unicode byte length. The REG_SZ entry in + * Windows registry may not have been stored with the proper + * terminating null characters: e.g. non null terminated string or a + * single byte null terminated. Refer below MSDN article on this: + * https://msdn.microsoft.com/en-us/library/windows/desktop/ms724884 + * %28v=vs.85%29.aspx Hence solution is to adjust the buffer length + * accordingly. Refer Bug 157010 for more details. + */ + if (lpcbData [0] % TCHAR.sizeof != 0) { + length++; + } if (length != 0) { /* Use the character encoding for the default locale */ TCHAR lpData = new TCHAR (0, length); |