const char* Parcel::ReadString() {
int l = Read<int>();
+ if (l <= 0)
+ return nullptr;
const char* str = reinterpret_cast<const char*>(&data_[reader_]);
+ if (static_cast<int>(strlen(str) + 1) != l)
+ return nullptr;
reader_ += l;
return str;
bundle* Parcel::ReadBundle() {
int l = Read<int>();
+ if (l <= 0)
+ return nullptr;
const bundle_raw* str = reinterpret_cast<const bundle_raw*>(&data_[reader_]);
+ if (static_cast<int>(strlen(reinterpret_cast<const char*>(str)) + 1) != l)
+ return nullptr;
reader_ += l;
bundle* b = bundle_decode(str, l - 1);
}
void Parcel::Read(unsigned char* buf, unsigned int size) {
+ if (reader_ + size > data_.size())
+ return;
std::copy(&data_[reader_], &data_[reader_] + size, buf);
reader_ += size;
}
template<typename T>
T Read() {
- T d;
+ T d = 0;
unsigned char* p = reinterpret_cast<unsigned char*>(&d);
+ if (reader_ + sizeof(T) > data_.size())
+ return d;
std::copy(&data_[reader_], &data_[reader_] + sizeof(T), p);
reader_ += sizeof(T);
return d;
return RPC_PORT_ERROR_INVALID_PARAMETER;
Parcel* p = static_cast<Parcel*>(h);
-
- *str = strdup(p->ReadString());
+ const char* read = p->ReadString();
+ *str = read == nullptr ? strdup("") : strdup(read);
return RPC_PORT_ERROR_NONE;
}
return RPC_PORT_ERROR_INVALID_PARAMETER;
Parcel* p = static_cast<Parcel*>(h);
+ bundle* read = p->ReadBundle();
- *b = p->ReadBundle();
+ *b = read == nullptr ? bundle_create() : read;
return RPC_PORT_ERROR_NONE;
}