summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Bingner <sam@bingner.com>2020-04-06 09:43:46 -1000
committerSam Bingner <sam@bingner.com>2020-04-08 13:58:02 -1000
commit004f27bdfbb548d87be5c6f327109e76b973a1ce (patch)
treed78d5014c757c20a8e11e27b583d5b93cbd03596
parent87cfa306c348a32cdeb646ec6ce283023cfc85f6 (diff)
Actually fix strange metadata.cb0 crashesv1.1.32%b26
-rw-r--r--Cytore.hpp28
-rw-r--r--MobileCydia.mm14
2 files changed, 28 insertions, 14 deletions
diff --git a/Cytore.hpp b/Cytore.hpp
index c0bad09..fb17aaa 100644
--- a/Cytore.hpp
+++ b/Cytore.hpp
@@ -140,6 +140,15 @@ class File {
blocks_.push_back(bytes + Block_ * i);
}
+ void Close_() {
+ for (typename MappingVector_::const_iterator map(maps_.begin()); map != maps_.end(); ++map)
+ munmap(map->data_, map->size_);
+ maps_.clear();
+ blocks_.clear();
+ close(file_);
+ file_ = -1;
+ }
+
bool Truncate_(size_t capacity) {
capacity = Round(capacity, Block_);
@@ -164,9 +173,7 @@ class File {
}
~File() {
- for (typename MappingVector_::const_iterator map(maps_.begin()); map != maps_.end(); ++map)
- munmap(map->data_, map->size_);
- close(file_);
+ Close_();
}
void Sync() {
@@ -182,6 +189,8 @@ class File {
_assert(file_ == -1);
file_ = open(path, O_RDWR | O_CREAT | O_EXLOCK, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
_assert(file_ != -1);
+ _assert(file_ != STDOUT_FILENO);
+ _assert(file_ != STDERR_FILENO);
struct stat stat;
_assert(fstat(file_, &stat) == 0);
@@ -197,16 +206,11 @@ class File {
Header_().magic_ = Magic;
Size_() = core;
- } else if (size < core) {
- close(file_);
- file_ = -1;
- unlink(path);
+ // XXX: this involves an unneccessary call to ftruncate()
+ } else if (size < core || !Truncate_(size) || Header_().magic_ != Magic || Header_().version_ != 0) {
+ Close_();
+ _assert(unlink(path) == 0);
goto open;
- } else {
- // XXX: this involves an unneccessary call to ftruncate()
- _assert(Truncate_(size));
- _assert(Header_().magic_ == Magic);
- _assert(Header_().version_ == 0);
}
}
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 9fd0a98..2fffce3 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -9352,9 +9352,19 @@ int main(int argc, char *argv[]) {
if ([WebPreferences respondsToSelector:@selector(setWebKitLinkTimeVersion:)])
[WebPreferences setWebKitLinkTimeVersion:PACKED_VERSION(3453,0,0)];
+ // Ensure we have a stdout and stderr
int fd(open("/tmp/cydia.log", O_WRONLY | O_APPEND | O_CREAT, 0644));
- dup2(fd, 2);
- close(fd);
+ // Added this because stderr output ended up in metadata.cb0 somehow once
+ // Perhaps we were spawned with stderr or stdout closed?
+ //
+ // Ensure we have a stdout and stderr
+ if (fcntl(STDOUT_FILENO, F_GETFD) == -1) {
+ dup2(fd, STDOUT_FILENO);
+ }
+ dup2(fd, STDERR_FILENO);
+ if (fd > STDERR_FILENO) {
+ close(fd);
+ }
NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);