Skip to content

Commit 699c429

Browse files
committed
8292866: Java_sun_awt_shell_Win32ShellFolder2_getLinkLocation check MultiByteToWideChar return value for failures
Reviewed-by: mdoerr, stuefe
1 parent 68da02c commit 699c429

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/java.desktop/windows/native/libawt/windows/ShellFolder2.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -700,6 +700,7 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getLinkLocation
700700
STRRET strret;
701701
OLECHAR olePath[MAX_PATH]; // wide-char version of path name
702702
LPWSTR wstr;
703+
int ret;
703704

704705
IShellFolder* pParent = (IShellFolder*)parentIShellFolder;
705706
if (pParent == NULL) {
@@ -719,12 +720,18 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getLinkLocation
719720
switch (strret.uType) {
720721
case STRRET_CSTR :
721722
// IShellFolder::ParseDisplayName requires the path name in Unicode.
722-
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, strret.cStr, -1, olePath, MAX_PATH);
723+
ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, strret.cStr, -1, olePath, MAX_PATH);
724+
if (ret == 0) {
725+
return NULL;
726+
}
723727
wstr = olePath;
724728
break;
725729

726730
case STRRET_OFFSET :
727-
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (CHAR *)pidl + strret.uOffset, -1, olePath, MAX_PATH);
731+
ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (CHAR *)pidl + strret.uOffset, -1, olePath, MAX_PATH);
732+
if (ret == 0) {
733+
return NULL;
734+
}
728735
wstr = olePath;
729736
break;
730737

0 commit comments

Comments
 (0)