From 2abdbea908d3a87681eedbb6fffabb4735947658 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 5 Sep 2026 04:16:48 -0400 Subject: [PATCH] unix: Deprecate the POSIX-obsoleted `tmpnam`, `tempnam` `tmpnam` is TOCTOU-prone and not thread-safe if called with NULL, and has been marked obsolete by POSIX [1] and glibc [2]. `tempnam` is also TOCTOU-prone and marked obsolete by POSIX [3], and glib docs say "Never use this function". We don't have these on all platforms, but mark them deprecated where they still exist. Closes: https://github.com/rust-lang/libc/issues/5211 [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/tmpnam.html [2]: https://man7.org/linux/man-pages/man3/tmpnam.3.html [3]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tempnam.html [4]: https://man7.org/linux/man-pages/man3/tempnam.3.html --- src/fuchsia/mod.rs | 4 ++++ src/new/qurt/stdio.rs | 4 ++++ src/solid/mod.rs | 8 ++++++++ src/unix/mod.rs | 4 ++++ src/vxworks/mod.rs | 4 ++++ 5 files changed, 24 insertions(+) diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 11a046720ceeb..5206bb78acc38 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -3828,6 +3828,10 @@ extern "C" { pub fn mkstemp(template: *mut c_char) -> c_int; pub fn mkdtemp(template: *mut c_char) -> *mut c_char; + #[deprecated( + since = "0.2.190", + note = "function is obsolete; prefer tmpfile, mkstemp, or similar" + )] pub fn tmpnam(ptr: *mut c_char) -> *mut c_char; pub fn openlog(ident: *const c_char, logopt: c_int, facility: c_int); diff --git a/src/new/qurt/stdio.rs b/src/new/qurt/stdio.rs index 7130717764e8a..191bdda3fb4c8 100644 --- a/src/new/qurt/stdio.rs +++ b/src/new/qurt/stdio.rs @@ -65,6 +65,10 @@ extern "C" { pub fn remove(filename: *const c_char) -> c_int; pub fn rename(old: *const c_char, new: *const c_char) -> c_int; pub fn tmpfile() -> *mut FILE; + #[deprecated( + since = "0.2.190", + note = "function is obsolete; prefer tmpfile, mkstemp, or similar" + )] pub fn tmpnam(s: *mut c_char) -> *mut c_char; // Buffer control diff --git a/src/solid/mod.rs b/src/solid/mod.rs index 7184ccf05719c..2b096231d7aba 100644 --- a/src/solid/mod.rs +++ b/src/solid/mod.rs @@ -461,6 +461,10 @@ extern "C" { pub fn vprintf(arg1: *const c_char, arg2: __va_list) -> c_int; pub fn gets(arg1: *mut c_char) -> *mut c_char; pub fn sprintf(arg1: *mut c_char, arg2: *const c_char, ...) -> c_int; + #[deprecated( + since = "0.2.190", + note = "function is obsolete; prefer tmpfile, mkstemp, or similar" + )] pub fn tmpnam(arg1: *const c_char) -> *mut c_char; pub fn vsprintf(arg1: *mut c_char, arg2: *const c_char, arg3: __va_list) -> c_int; pub fn rename(arg1: *const c_char, arg2: *const c_char) -> c_int; @@ -507,6 +511,10 @@ extern "C" { ) -> c_int; pub fn getw(arg1: *mut FILE) -> c_int; pub fn putw(arg1: c_int, arg2: *mut FILE) -> c_int; + #[deprecated( + since = "0.2.190", + note = "function is obsolete; prefer tmpfile, mkstemp, or similar" + )] pub fn tempnam(arg1: *const c_char, arg2: *const c_char) -> *mut c_char; pub fn fseeko(stream: *mut FILE, offset: off_t, whence: c_int) -> c_int; pub fn ftello(stream: *mut FILE) -> off_t; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index cab7698942551..b317f2ea72d29 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -2156,6 +2156,10 @@ extern "C" { pub fn mkstemp(template: *mut c_char) -> c_int; pub fn mkdtemp(template: *mut c_char) -> *mut c_char; + #[deprecated( + since = "0.2.190", + note = "function is obsolete; prefer tmpfile, mkstemp, or similar" + )] pub fn tmpnam(ptr: *mut c_char) -> *mut c_char; pub fn openlog(ident: *const c_char, logopt: c_int, facility: c_int); diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index e09ca2af29659..de6f7233337ac 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -1776,6 +1776,10 @@ extern "C" { pub fn ftello(stream: *mut crate::FILE) -> off_t; pub fn mkstemp(template: *mut c_char) -> c_int; + #[deprecated( + since = "0.2.190", + note = "function is obsolete; prefer tmpfile, mkstemp, or similar" + )] pub fn tmpnam(ptr: *mut c_char) -> *mut c_char; pub fn openlog(ident: *const c_char, logopt: c_int, facility: c_int);