netcat: switch mktemp() → mkstemp() to silence GCC/ld warning on Linux
apps/nc/netcat.c still calls mktemp().
LibreSSL already keeps a small set of local patches on top of the upstream OpenBSD source, so this change can be added to the same patch block.
On Linux (GCC + glibc) the linker prints:
…/netcat.c:470: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
Suggested patch (fits into the existing netcat.c patch block)
- if (mktemp(unix_dg_tmp_socket_buf) == NULL)
- err(1, "mktemp");
+ int fd = mkstemp(unix_dg_tmp_socket_buf);
+ if (fd == -1)
+ err(1, "mkstemp");
+ close(fd);
+ unlink(unix_dg_tmp_socket_buf);
It is a known issue and it is annoying. I do not want to add this patch since it does not fix anything. There is no problem that is solved with this patch. The linker warning is a warning and it does not apply in this case and in no way is using one of the suggested alternatives better.
People have tried to upstream similar changes and they were rejected: https://marc.info/?l=openbsd-tech&m=173056731630093&w=2
The way I believe we should try to solve this is as follows: we have a mktemp implementation in openrsync that can create a socket: https://github.com/openbsd/src/blob/7639f02327c4dddc3a3d0bd41f882fd3514a054a/usr.bin/rsync/mktemp.c#L162 if we can drop this into netcat, we get rid of the races and the warnings. It is of course going to be a bit more complicated than your patch.