From 55a34b69f3a3c438254657da49205158793e21e3 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 19 Jun 2011 22:14:09 +0200 Subject: [PATCH] fs_write_attr(): Allow 0-length NULL buffer --- src/build/libroot/fs_attr_untyped.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/build/libroot/fs_attr_untyped.cpp b/src/build/libroot/fs_attr_untyped.cpp index 6276dcff26..02ea2af095 100644 --- a/src/build/libroot/fs_attr_untyped.cpp +++ b/src/build/libroot/fs_attr_untyped.cpp @@ -566,7 +566,7 @@ fs_write_attr(int fd, const char *_attribute, uint32 type, off_t pos, { // check params if (pos < 0 || pos + writeBytes > kMaxAttributeLength - || !_attribute || !buffer) { + || _attribute == NULL || (writeBytes > 0 && buffer == NULL)) { errno = B_BAD_VALUE; return -1; } @@ -587,7 +587,10 @@ fs_write_attr(int fd, const char *_attribute, uint32 type, off_t pos, AttributeHeader* header = (AttributeHeader*)attributeBuffer; header->type = type; memset(attributeBuffer + sizeof(AttributeHeader), 0, pos); - memcpy(attributeBuffer + sizeof(AttributeHeader) + pos, buffer, writeBytes); + if (writeBytes > 0) { + memcpy(attributeBuffer + sizeof(AttributeHeader) + pos, buffer, + writeBytes); + } // write the attribute ssize_t toWrite = sizeof(AttributeHeader) + pos + writeBytes;