diff --git a/src/header/pthread/mod.rs b/src/header/pthread/mod.rs
index b4bd9ab9eef0865263930b2eb8e52e609264371e..0b8a6ba0308e8c710c53f6727e5b5721902466c1 100644
--- a/src/header/pthread/mod.rs
+++ b/src/header/pthread/mod.rs
@@ -1,6 +1,6 @@
 //! pthread.h implementation for Redox, following https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html
 
-use core::cell::Cell;
+use core::{cell::Cell, ptr::NonNull};
 
 use crate::{
     header::{sched::*, time::timespec},
@@ -188,7 +188,11 @@ pub unsafe extern "C" fn pthread_self() -> pthread_t {
 pub unsafe extern "C" fn pthread_setcancelstate(state: c_int, oldstate: *mut c_int) -> c_int {
     match pthread::set_cancel_state(state) {
         Ok(old) => {
-            oldstate.write(old);
+            // POSIX doesn't imply oldstate can be NULL anywhere, but a lot of C code probably
+            // relies on it...
+            if let Some(oldstate) = NonNull::new(oldstate) {
+                oldstate.write(old);
+            }
             0
         }
         Err(pthread::Errno(error)) => error,
@@ -198,7 +202,11 @@ pub unsafe extern "C" fn pthread_setcancelstate(state: c_int, oldstate: *mut c_i
 pub unsafe extern "C" fn pthread_setcanceltype(ty: c_int, oldty: *mut c_int) -> c_int {
     match pthread::set_cancel_type(ty) {
         Ok(old) => {
-            oldty.write(old);
+            // POSIX doesn't imply oldty can be NULL anywhere, but a lot of C code probably relies
+            // on it...
+            if let Some(oldty) = NonNull::new(oldty) {
+                oldty.write(old);
+            }
             0
         }
         Err(pthread::Errno(error)) => error,
diff --git a/tests/Makefile b/tests/Makefile
index d98fee8e43e5a6ae45de3a475f60c13718e0d264..df8938f351da29cb886f4c97ba0977a4d2b71e1b 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -25,7 +25,6 @@ EXPECT_NAMES=\
 	math \
 	netdb/getaddrinfo \
 	ptrace \
-	pty/forkpty \
 	regex \
 	select \
 	setjmp \
@@ -158,6 +157,7 @@ DYNAMIC_ONLY_NAMES=\
 NAMES=\
 	$(EXPECT_NAMES) \
 	dirent/main \
+	pty/forkpty \
 	pwd \
 	sa_restart \
 	sigchld \
diff --git a/tests/stdio/dprintf.c b/tests/stdio/dprintf.c
index 766012818ca0bbde8f209900aa28a56f4c5aeee8..b61d5cfa9782dc385e3ef463f78930ab32deb2e8 100644
--- a/tests/stdio/dprintf.c
+++ b/tests/stdio/dprintf.c
@@ -1,15 +1,14 @@
 #include <stdio.h>
-#include <fcntl.h>
+#include <unistd.h>
 
 #include "test_helpers.h"
 
-int main(void)
-{
-    int fd = open("/dev/stdout", O_WRONLY, 0222);
-    ERROR_IF(open, fd, < 0);
-
+int main(void) {
     const char *msg = "Hello, %s";
 
+    int fd = dup(STDOUT_FILENO);
+    ERROR_IF(dup, fd, == -1);
+
     int result = dprintf(fd, msg, "world");
     ERROR_IF(dprintf, result, != sizeof("Hello, world") - 1);
     UNEXP_IF(dprintf, result, < 0);
@@ -21,4 +20,4 @@ int main(void)
     close(fd);
 
     return 0;
-}
\ No newline at end of file
+}