From be8f1fea763f42a1109f6b1eb3f56ae521cfdec3 Mon Sep 17 00:00:00 2001 From: millert <> Date: Fri, 19 Jan 2024 19:45:02 +0000 Subject: Make our mktemp(3) callback-driven and split into multiple files. Previously, calling any of the mktemp(3) family would pull in lstat(2), open(2) and mkdir(2). Now, only the necessary system calls will be reachable from the binary. OK deraadt@ guenther@ --- src/lib/libc/stdlib/mkdtemp.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/lib/libc/stdlib/mkdtemp.c (limited to 'src/lib/libc/stdlib/mkdtemp.c') diff --git a/src/lib/libc/stdlib/mkdtemp.c b/src/lib/libc/stdlib/mkdtemp.c new file mode 100644 index 0000000000..c33c3b4e8b --- /dev/null +++ b/src/lib/libc/stdlib/mkdtemp.c @@ -0,0 +1,33 @@ +/* $OpenBSD: mkdtemp.c,v 1.1 2024/01/19 19:45:02 millert Exp $ */ +/* + * Copyright (c) 2024 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +static int +mkdtemp_cb(const char *path, int flags) +{ + return mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR); +} + +char * +mkdtemp(char *path) +{ + if (__mktemp4(path, 0, 0, mkdtemp_cb) == 0) + return path; + return NULL; +} -- cgit v1.2.3-55-g6feb