Fix execution bug w/o binfmt_misc

The longjmp relocation in the master boot record coincidentally had a
quote character in it, which caused the master boot record to be used
when interpreter by the shell. The solution, is to move the grub stub
below the long mode loader so the real mode loader relocation is near
the master boot record. This change includes a regression test.
This commit is contained in:
Justine Tunney 2022-05-25 17:19:46 -07:00
parent 1a29424c52
commit 8f12cd980d
3 changed files with 61 additions and 46 deletions

View file

@ -105,6 +105,20 @@ void RunApeTest(const char *path) {
EXPECT_STREQN("MZqFpD", buf, 6);
}
TEST(ape, noAccidentalQuotesInMasterBootRecord) {
int i, quotes = 0;
char buf[512] = {0};
EXPECT_SYS(0, 3, open("bin/apetest.com", O_RDONLY));
EXPECT_SYS(0, 512, read(3, buf, 512));
EXPECT_SYS(0, 0, close(3));
for (i = 0; i < 512; ++i) {
if (buf[i] == '\'') {
++quotes;
}
}
EXPECT_EQ(1, quotes);
}
TEST(apeNoModifySelf, runsWithoutModifyingSelf) {
RunApeTest("bin/apetest.com");
}