test_utils: Test whether mmap PROT_WRITE fails

Writing is what our guard is supposed to prevent, let's try to mmap it
for writing. It seems FreeBSD still allows PROT_READ for sealed-for-writing
mmaps.
This commit is contained in:
Kai Uwe Broulik 2022-10-24 19:02:36 +02:00
parent 7da79f5ec4
commit 1393f524ff

View file

@ -57,10 +57,10 @@ void TestUtils::testSealedRamFile()
QCOMPARE(written, -1);
// Cannot use MAP_SHARED on sealed file descriptor.
void *data = mmap(nullptr, file.size(), PROT_READ, MAP_SHARED, file.fd(), 0);
void *data = mmap(nullptr, file.size(), PROT_WRITE, MAP_SHARED, file.fd(), 0);
QCOMPARE(data, MAP_FAILED);
data = mmap(nullptr, file.size(), PROT_READ, MAP_PRIVATE, file.fd(), 0);
data = mmap(nullptr, file.size(), PROT_WRITE, MAP_PRIVATE, file.fd(), 0);
QVERIFY(data != MAP_FAILED);
#else
QSKIP("Sealing requires memfd suport.");