summaryrefslogtreecommitdiff
path: root/MobileCydia.mm
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2014-05-17 01:43:58 -0700
committerJay Freeman (saurik) <saurik@saurik.com>2014-05-17 01:43:58 -0700
commitac5f7cb30c6a09d809e2d9fea2824b100c8093d4 (patch)
treea7b45f90d4735df51eed35b6707467768f9752c1 /MobileCydia.mm
parent3f88f20507c0870b890db839c17186d6928fae29 (diff)
Don't rely on null-terminated name in PackageFind.
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r--MobileCydia.mm18
1 files changed, 10 insertions, 8 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 900e76e..e207fa3 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -1304,7 +1304,7 @@ static PackageValue *PackageFind(const char *name, size_t length, bool *fail = N
PackageValue *metadata;
Cytore::Offset<PackageValue> *offset(&MetaFile_->packages_[nhash.u16[0]]);
- offset: if (offset->IsNull()) {
+ for (;; offset = &metadata->next_) { if (offset->IsNull()) {
*offset = MetaFile_.New<PackageValue>(length + 1);
metadata = &MetaFile_.Get(*offset);
@@ -1316,16 +1316,18 @@ static PackageValue *PackageFind(const char *name, size_t length, bool *fail = N
memset(metadata, 0, sizeof(*metadata));
}
- memcpy(metadata->name_, name, length + 1);
+ memcpy(metadata->name_, name, length);
+ metadata->name_[length] = '\0';
metadata->nhash_ = nhash.u16[1];
} else {
metadata = &MetaFile_.Get(*offset);
-
- if (metadata->nhash_ != nhash.u16[1] || strncmp(metadata->name_, name, length + 1) != 0) {
- offset = &metadata->next_;
- goto offset;
- }
- }
+ if (metadata->nhash_ != nhash.u16[1])
+ continue;
+ if (strncmp(metadata->name_, name, length) != 0)
+ continue;
+ if (metadata->name_[length] != '\0')
+ continue;
+ } break; }
return metadata;
}