From b052fcbb2cd1959d665ca39dc73823d9d40e24a4 Mon Sep 17 00:00:00 2001 From: James Howard Date: Sat, 18 May 2019 22:39:54 -0500 Subject: [PATCH 1/2] Avoid truncating final char when macOS getXAttr reads xattr lacking null termination. --- CHANGES.md | 1 + contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 11b4eca758..0f42c2842c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Features Bug Fixes --------- +* Avoid truncating final character when macOS getXAttr reads a non-null-terminated xattr, e.g. an xattr created using `xattr -w user.sample 1 myfile.txt`. * [#1091](https://github.com/java-native-access/jna/issues/1091): Check target number to be greater than zero, before calling `Structure#toArray` in `c.s.j.p.win32.Netapi32Util` - [@trevormagg](https://github.com/trevormaggs), [@matthiasblaesing](https://github.com/matthiasblaesing). Release 5.3.1 diff --git a/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java b/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java index 09085d8d47..5870e9da2d 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java @@ -67,7 +67,7 @@ public static String getXAttr(String path, String name) { if (valueLength < 0) return null; - return decodeString(valueBuffer.getByteBuffer(0, valueLength - 1)); + return decodeString(valueBuffer.getByteBuffer(0, valueLength)).replace("\0",""); } public static int setXAttr(String path, String name, String value) { From 91a1c1f99efd993821b93dad7ee4e47a46a93980 Mon Sep 17 00:00:00 2001 From: James Howard Date: Sat, 18 May 2019 23:07:40 -0500 Subject: [PATCH 2/2] Avoid including null termination as part of macOS setXAttr. --- CHANGES.md | 1 + contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0f42c2842c..faa04b54fb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Features Bug Fixes --------- * Avoid truncating final character when macOS getXAttr reads a non-null-terminated xattr, e.g. an xattr created using `xattr -w user.sample 1 myfile.txt`. +* Avoid including null termination as part of macOS setXAttr. * [#1091](https://github.com/java-native-access/jna/issues/1091): Check target number to be greater than zero, before calling `Structure#toArray` in `c.s.j.p.win32.Netapi32Util` - [@trevormagg](https://github.com/trevormaggs), [@matthiasblaesing](https://github.com/matthiasblaesing). Release 5.3.1 diff --git a/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java b/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java index 5870e9da2d..05371d206a 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java @@ -67,12 +67,12 @@ public static String getXAttr(String path, String name) { if (valueLength < 0) return null; - return decodeString(valueBuffer.getByteBuffer(0, valueLength)).replace("\0",""); + return decodeString(valueBuffer.getByteBuffer(0, valueLength)); } public static int setXAttr(String path, String name, String value) { Memory valueBuffer = encodeString(value); - return XAttr.INSTANCE.setxattr(path, name, valueBuffer, valueBuffer.size(), 0, 0); + return XAttr.INSTANCE.setxattr(path, name, valueBuffer, valueBuffer.size() - 1, 0, 0); } public static int removeXAttr(String path, String name) {