Fix some bugs with dup2() and ZipOS

On UNIX if dup2(newfd) was a ZipOS file descriptor, then its resources
weren't being released, and the newly created file descriptor would be
mistaken for ZipOS due to its memory not being cleared. On Windows, an
issue also existed relating to newfd resources not being released.
This commit is contained in:
Justine Tunney 2023-11-30 10:10:02 -08:00
parent 26c70e08bf
commit 4b7ba9a4c5
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
4 changed files with 36 additions and 3 deletions

View file

@ -33,6 +33,8 @@
#include "libc/testlib/testlib.h"
#include "libc/x/xspawn.h"
__static_yoink("libc/testlib/hyperion.txt");
void SetUpOnce(void) {
testlib_enable_tmp_setup_teardown();
}
@ -50,7 +52,6 @@ static textstartup void TestInit(int argc, char **argv) {
const void *const TestCtor[] initarray = {TestInit};
#if 0
TEST(dup, ebadf) {
ASSERT_SYS(EBADF, -1, dup(-1));
ASSERT_SYS(EBADF, -1, dup2(-1, 0));
@ -72,7 +73,17 @@ TEST(dup, bigNumber) {
ASSERT_SYS(0, 100, dup2(0, 100));
ASSERT_SYS(0, 0, close(100));
}
#endif
TEST(dup2, zipos) {
ASSERT_SYS(0, 3, creat("real", 0644));
ASSERT_SYS(0, 4, open("/zip/libc/testlib/hyperion.txt", O_RDONLY));
ASSERT_SYS(0, 2, write(3, "hi", 2));
ASSERT_SYS(EBADF, -1, write(4, "hi", 2));
ASSERT_SYS(0, 4, dup2(3, 4));
ASSERT_SYS(0, 2, write(4, "hi", 2));
ASSERT_SYS(0, 0, close(4));
ASSERT_SYS(0, 0, close(3));
}
#ifdef __x86_64__
TEST(dup, clearsCloexecFlag) {