Skip to content

Commit

Permalink
fix HFSPlusAttrKey length
Browse files Browse the repository at this point in the history
  • Loading branch information
xerub committed Jun 21, 2015
1 parent 5efc1e1 commit 67f60ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions hfs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <string.h>
#include <hfs/hfsplus.h>

#define ATTRKEYLEN(n) (sizeof(HFSPlusAttrKey) - sizeof(HFSUniStr255) + (sizeof(uint16_t) * (n))) // wut?

static inline void flipAttrData(HFSPlusAttrData* data) {
FLIPENDIAN(data->recordType);
FLIPENDIAN(data->size);
Expand Down Expand Up @@ -95,12 +97,12 @@ static int attrKeyWrite(off_t offset, BTKey* toWrite, io_func* io) {
uint16_t nodeNameLength;
int i;

keyLength = toWrite->keyLength;
nodeNameLength = ((HFSPlusAttrKey *)toWrite)->name.length;

keyLength = sizeof(uint16_t) * nodeNameLength + UNICODE_START;
key = (HFSPlusAttrKey*) malloc(keyLength);
memcpy(key, toWrite, keyLength);

nodeNameLength = key->name.length;

FLIPENDIAN(key->keyLength);
FLIPENDIAN(key->fileID);
FLIPENDIAN(key->startBlock);
Expand Down Expand Up @@ -175,7 +177,7 @@ static int updateAttributes(Volume* volume, HFSPlusAttrKey* skey, HFSPlusAttrRec
HFSPlusAttrRecord* record;
int ret, len;

memcpy(&key, skey, skey->keyLength);
memcpy(&key, skey, sizeof(uint16_t) * skey->name.length + UNICODE_START);

switch(srecord->recordType) {
case kHFSPlusAttrInlineData:
Expand Down Expand Up @@ -221,7 +223,7 @@ size_t getAttribute(Volume* volume, uint32_t fileID, const char* name, uint8_t**
key.fileID = fileID;
key.startBlock = 0;
ASCIIToUnicode(name, &key.name);
key.keyLength = sizeof(HFSPlusAttrKey) - sizeof(HFSUniStr255) + sizeof(key.name.length) + (sizeof(uint16_t) * key.name.length);
key.keyLength = ATTRKEYLEN(key.name.length);

*data = NULL;

Expand Down Expand Up @@ -260,7 +262,7 @@ int setAttribute(Volume* volume, uint32_t fileID, const char* name, uint8_t* dat
key.fileID = fileID;
key.startBlock = 0;
ASCIIToUnicode(name, &key.name);
key.keyLength = sizeof(HFSPlusAttrKey) - sizeof(HFSUniStr255) + sizeof(key.name.length) + (sizeof(uint16_t) * key.name.length);
key.keyLength = ATTRKEYLEN(key.name.length);

record = (HFSPlusAttrData*) malloc(sizeof(HFSPlusAttrData) + size);
memset(record, 0, sizeof(HFSPlusAttrData));
Expand All @@ -285,7 +287,7 @@ int unsetAttribute(Volume* volume, uint32_t fileID, const char* name) {
key.fileID = fileID;
key.startBlock = 0;
ASCIIToUnicode(name, &key.name);
key.keyLength = sizeof(HFSPlusAttrKey) - sizeof(HFSUniStr255) + sizeof(key.name.length) + (sizeof(uint16_t) * key.name.length);
key.keyLength = ATTRKEYLEN(key.name.length);
return removeFromBTree(volume->attrTree, (BTKey*)(&key));
}

Expand All @@ -309,7 +311,7 @@ XAttrList* getAllExtendedAttributes(HFSCatalogNodeID CNID, Volume* volume) {
key.fileID = CNID;
key.startBlock = 0;
key.name.length = 0;
key.keyLength = sizeof(HFSPlusAttrKey) - sizeof(HFSUniStr255) + sizeof(key.name.length) + (sizeof(uint16_t) * key.name.length);
key.keyLength = ATTRKEYLEN(key.name.length);

tree = volume->attrTree;
record = (HFSPlusAttrRecord*) search(tree, (BTKey*)(&key), NULL, &nodeNumber, &recordNumber);
Expand Down
2 changes: 1 addition & 1 deletion includes/hfs/hfsplus.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ struct HFSPlusAttrKey {
uint16_t pad;
uint32_t fileID;
uint32_t startBlock;
HFSUniStr255 name;
HFSUniStr255 name; /* should be 127, really */
} __attribute__((__packed__));
typedef struct HFSPlusAttrKey HFSPlusAttrKey;

Expand Down

0 comments on commit 67f60ba

Please sign in to comment.