mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-14 01:24:52 +00:00
GetZipCdir: prevent integer underflow. posix_spawn_test.c: stop attempting to load zipos from /usr/bin/ape. (#758)
This commit is contained in:
parent
22fcab131c
commit
c5de653b98
2 changed files with 8 additions and 7 deletions
|
@ -55,11 +55,12 @@ void *GetZipCdir(const uint8_t *p, size_t n) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (magic = READ32LE(p + i),
|
while (magic = READ32LE(p + i), magic != kZipCdir64LocatorMagic &&
|
||||||
magic != kZipCdir64LocatorMagic && magic != kZipCdirHdrMagic &&
|
magic != kZipCdirHdrMagic &&
|
||||||
i + 0x10000 + 0x1000 >= n) --i;
|
i + 0x10000 + 0x1000 >= n && i > 0) {
|
||||||
if (magic == kZipCdir64LocatorMagic &&
|
--i;
|
||||||
i + kZipCdir64LocatorSize <= n &&
|
}
|
||||||
|
if (magic == kZipCdir64LocatorMagic && i + kZipCdir64LocatorSize <= n &&
|
||||||
IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + i))) {
|
IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + i))) {
|
||||||
return p + ZIP_LOCATE64_OFFSET(p + i);
|
return p + ZIP_LOCATE64_OFFSET(p + i);
|
||||||
} else if (magic == kZipCdirHdrMagic && IsZipCdir32(p, n, i)) {
|
} else if (magic == kZipCdirHdrMagic && IsZipCdir32(p, n, i)) {
|
||||||
|
@ -73,6 +74,6 @@ void *GetZipCdir(const uint8_t *p, size_t n) {
|
||||||
} while (j-- && i - j < 128);
|
} while (j-- && i - j < 128);
|
||||||
return p + i;
|
return p + i;
|
||||||
}
|
}
|
||||||
} while (i-- + 0x10000 + 0x1000 >= n);
|
} while (i > 0 && i-- + 0x10000 + 0x1000 >= n);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ __attribute__((__constructor__)) static void init(void) {
|
||||||
TEST(posix_spawn, test) {
|
TEST(posix_spawn, test) {
|
||||||
int rc, ws, pid;
|
int rc, ws, pid;
|
||||||
char *prog = GetProgramExecutableName();
|
char *prog = GetProgramExecutableName();
|
||||||
char *args[] = {program_invocation_name, NULL};
|
char *args[] = {prog, NULL};
|
||||||
char *envs[] = {"THE_DOGE=42", NULL};
|
char *envs[] = {"THE_DOGE=42", NULL};
|
||||||
EXPECT_EQ(0, posix_spawn(&pid, prog, NULL, NULL, args, envs));
|
EXPECT_EQ(0, posix_spawn(&pid, prog, NULL, NULL, args, envs));
|
||||||
EXPECT_NE(-1, waitpid(pid, &ws, 0));
|
EXPECT_NE(-1, waitpid(pid, &ws, 0));
|
||||||
|
|
Loading…
Add table
Reference in a new issue