diff --git a/CHANGES.md b/CHANGES.md index ef944fcbb..5b4d1ae76 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Features Bug Fixes --------- +* [#1644](https://github.com/java-native-access/jna/issues/1644): Fix bug in VARDESC causing an illegal memory access - [@stmuecke](https://github.com/stmuecke) Release 5.15.0 ============== diff --git a/contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java b/contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java index 2cfd89616..9239f8851 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java @@ -1398,14 +1398,10 @@ public static class ByReference extends _VARDESC implements public VARIANT.ByReference lpvarValue; public _VARDESC() { - setType("lpvarValue"); - this.read(); } public _VARDESC(Pointer pointer) { super(pointer); - setType("lpvarValue"); - this.read(); } /** @@ -1431,9 +1427,15 @@ public VARDESC() { public VARDESC(Pointer pointer) { super(pointer); - this._vardesc.setType("lpvarValue"); this.read(); } + + @Override + public void read() { + readField("varkind"); + this._vardesc.setType(varkind.value == VARKIND.VAR_CONST ? "lpvarValue" : "oInst"); + super.read(); + } } @FieldOrder({"tdesc", "_elemdesc"}) @@ -1654,14 +1656,10 @@ public static class _TYPEDESC extends Union { public HREFTYPE hreftype; public _TYPEDESC() { - this.setType("hreftype"); - this.read(); } public _TYPEDESC(Pointer pointer) { super(pointer); - this.setType("hreftype"); - this.read(); } public TYPEDESC.ByReference getLptdesc() { @@ -1687,18 +1685,34 @@ public HREFTYPE getHreftype() { public VARTYPE vt; public TYPEDESC() { - this.read(); } public TYPEDESC(Pointer pointer) { super(pointer); - this.read(); } public TYPEDESC(_TYPEDESC _typedesc, VARTYPE vt) { this._typedesc = _typedesc; this.vt = vt; } + + @Override + public void read() { + readField("vt"); + switch (vt.intValue()) { + case Variant.VT_PTR : + case Variant.VT_SAFEARRAY : + _typedesc.setType("lptdesc"); + break; + case Variant.VT_CARRAY : + _typedesc.setType("lpadesc"); + break; + case Variant.VT_USERDEFINED : + _typedesc.setType("hreftype"); + break; + } + super.read(); + } } @FieldOrder({"dwReserved", "wIDLFlags"})