Loading...
--- xnu/xnu-12377.101.15/libkern/c++/OSSerializeBinary.cpp
+++ xnu/xnu-6153.121.1/libkern/c++/OSSerializeBinary.cpp
@@ -27,13 +27,10 @@
*/
-#include <libkern/c++/OSSharedPtr.h>
-#include <libkern/OSSerializeBinary.h>
#include <libkern/c++/OSContainers.h>
#include <libkern/c++/OSLib.h>
#include <libkern/c++/OSDictionary.h>
#include <libkern/OSSerializeBinary.h>
-#include <libkern/c++/OSSharedPtr.h>
#include <IOKit/IOLib.h>
@@ -111,7 +108,7 @@
bool
OSSerialize::addBinaryObject(const OSMetaClassBase * o, uint32_t key,
- const void * bits, uint32_t size,
+ const void * bits, size_t size,
uint32_t * startCollection)
{
unsigned int newCapacity;
@@ -129,7 +126,7 @@
headerSize += sizeof(uint32_t);
}
offset /= sizeof(uint32_t);
- indexData->appendValue(offset);
+ indexData->appendBytes(&offset, sizeof(offset));
}
if (os_add3_overflow(size, headerSize, 3, &alignSize)) {
@@ -218,8 +215,8 @@
OSBoolean * boo;
unsigned int tagIdx;
- uint32_t i, key, startCollection = 0;
- uint32_t len;
+ uint32_t i, key, startCollection;
+ size_t len;
bool ok;
tagIdx = tags->getNextIndexOfObject(o, 0);
@@ -308,7 +305,7 @@
key = (kOSSerializeSymbol | len);
ok = addBinaryObject(o, key, sym->getCStringNoCopy(), len, NULL);
} else if ((str = OSDynamicCast(OSString, o))) {
- len = str->getLength();
+ len = (str->getLength() + ((indexData != NULL) ? 1 : 0));
key = (kOSSerializeString | len);
ok = addBinaryObject(o, key, str->getCStringNoCopy(), len, NULL);
} else if ((ldata = OSDynamicCast(OSData, o))) {
@@ -327,19 +324,28 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-#define setAtIndex(v, idx, o) \
- ok = idx < v##Capacity; \
- if (!ok && v##Capacity < v##CapacityMax) { \
- uint32_t ncap = v##Capacity + 64; \
- typeof(v##Array) nbuf = kreallocp_type_container(OSObject *, \
- v##Array, v##Capacity, &ncap, Z_WAITOK_ZERO); \
- if (nbuf) { \
- ok = true; \
- v##Array = nbuf; \
- v##Capacity = ncap; \
- } \
- } \
- if (ok) v##Array[idx] = o
+#define setAtIndex(v, idx, o) \
+ if (idx >= v##Capacity) \
+ { \
+ if (v##Capacity >= v##CapacityMax) ok = false; \
+ else \
+ { \
+ uint32_t ncap = v##Capacity + 64; \
+ typeof(v##Array) nbuf = (typeof(v##Array)) kalloc_container(ncap * sizeof(o)); \
+ if (!nbuf) ok = false; \
+ else \
+ { \
+ if (v##Array) \
+ { \
+ bcopy(v##Array, nbuf, v##Capacity * sizeof(o)); \
+ kfree(v##Array, v##Capacity * sizeof(o)); \
+ } \
+ v##Array = nbuf; \
+ v##Capacity = ncap; \
+ } \
+ } \
+ } \
+ if (ok) v##Array[idx] = o;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -372,10 +378,7 @@
const uint32_t * next;
uint32_t key, len, wordLen, length;
bool end, newCollect, isRef;
- union {
- unsigned long long value;
- double fpValue;
- } value;
+ unsigned long long value;
bool ok, indexed, hasLength;
indexed = false;
@@ -458,23 +461,13 @@
if (bufferPos > bufferSize) {
break;
}
- value.value = next[1];
- value.value <<= 32;
- value.value |= next[0];
- switch (len) {
- case 63:
- o = OSNumber::withDouble(value.fpValue);
- break;
- case 31:
- o = OSNumber::withFloat((float) value.fpValue);
- break;
- case 64:
- case 32:
- case 16:
- case 8:
- o = OSNumber::withNumber(value.value, len);
- break;
- }
+ if ((len != 32) && (len != 64) && (len != 16) && (len != 8)) {
+ break;
+ }
+ value = next[1];
+ value <<= 32;
+ value |= next[0];
+ o = OSNumber::withNumber(value, len);
next += 2;
break;
@@ -483,7 +476,7 @@
if (bufferPos > bufferSize) {
break;
}
- if (len < 1) {
+ if (len < 2) {
break;
}
if (0 != ((const char *)next)[len - 1]) {
@@ -498,7 +491,7 @@
if (bufferPos > bufferSize) {
break;
}
- o = OSString::withCString((const char *) next, len);
+ o = OSString::withStringOfLength((const char *) next, len);
next += wordLen;
break;
@@ -526,7 +519,6 @@
if (hasLength) {
bufferPos += sizeof(*next);
if (!(ok = (bufferPos <= bufferSize))) {
- o->release();
break;
}
length = *next++;
@@ -627,52 +619,11 @@
for (len = (result != NULL); len < objsIdx; len++) {
objsArray[len]->release();
}
- kfree_type(OSObject *, objsCapacity, objsArray);
+ kfree(objsArray, objsCapacity * sizeof(*objsArray));
}
if (stackCapacity) {
- kfree_type(OSObject *, stackCapacity, stackArray);
+ kfree(stackArray, stackCapacity * sizeof(*stackArray));
}
return result;
}
-
-OSObject*
-OSUnserializeXML(
- const char * buffer,
- OSSharedPtr<OSString>& errorString)
-{
- OSString* errorStringRaw = NULL;
- OSObject* result = OSUnserializeXML(buffer, &errorStringRaw);
- errorString.reset(errorStringRaw, OSNoRetain);
- return result;
-}
-
-OSObject*
-OSUnserializeXML(
- const char * buffer,
- size_t bufferSize,
- OSSharedPtr<OSString> &errorString)
-{
- OSString* errorStringRaw = NULL;
- OSObject* result = OSUnserializeXML(buffer, bufferSize, &errorStringRaw);
- errorString.reset(errorStringRaw, OSNoRetain);
- return result;
-}
-
-OSObject*
-OSUnserializeBinary(const char *buffer, size_t bufferSize, OSSharedPtr<OSString>& errorString)
-{
- OSString* errorStringRaw = NULL;
- OSObject* result = OSUnserializeBinary(buffer, bufferSize, &errorStringRaw);
- errorString.reset(errorStringRaw, OSNoRetain);
- return result;
-}
-
-OSObject*
-OSUnserialize(const char *buffer, OSSharedPtr<OSString>& errorString)
-{
- OSString* errorStringRaw = NULL;
- OSObject* result = OSUnserialize(buffer, &errorStringRaw);
- errorString.reset(errorStringRaw, OSNoRetain);
- return result;
-}