Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid exception when getting zero-length xattr on mac #1041

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ Bug Fixes
* Ensure structure size is calculated prior to converting to array
* Avoid creating new windows when setting a window mask
* Fix bug in Pointer.setChar.
* Avoid IllegalArgumentException when reading xattrs with zero length

Release 3.0
===========
Expand Down
12 changes: 12 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/linux/XAttrUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ public static Memory getXAttrAsMemory(String path, String name) throws IOExcepti
throw new IOException("errno: " + eno);
}

if (retval.longValue() == 0) {
return null;
}

valueMem = new Memory(retval.longValue());
retval = XAttr.INSTANCE.getxattr(path, name, valueMem, new size_t(valueMem.size()));
if (retval.longValue() < 0) {
Expand Down Expand Up @@ -352,6 +356,10 @@ public static Memory lGetXAttrAsMemory(String path, String name) throws IOExcept
throw new IOException("errno: " + eno);
}

if (retval.longValue() == 0) {
return null;
}

valueMem = new Memory(retval.longValue());
retval = XAttr.INSTANCE.lgetxattr(path, name, valueMem, new size_t(valueMem.size()));
if (retval.longValue() < 0) {
Expand Down Expand Up @@ -445,6 +453,10 @@ public static Memory fGetXAttrAsMemory(int fd, String name) throws IOException {
throw new IOException("errno: " + eno);
}

if (retval.longValue() == 0) {
return null;
}

valueMem = new Memory(retval.longValue());
retval = XAttr.INSTANCE.fgetxattr(fd, name, valueMem, new size_t(valueMem.size()));
if (retval.longValue() < 0) {
Expand Down
3 changes: 3 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public static String getXAttr(String path, String name) {
if (bufferLength < 0)
return null;

if (bufferLength == 0)
return "";

Memory valueBuffer = new Memory(bufferLength);
long valueLength = XAttr.INSTANCE.getxattr(path, name, valueBuffer, bufferLength, 0, 0);

Expand Down