summaryrefslogtreecommitdiff
path: root/util/libreboot-utils
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-24 20:23:00 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-24 21:31:33 +0000
commitb8a045ef86ab439accc0717daeb841aa065b86d6 (patch)
tree3ff8e4f924076cd9e3197e5a1d92c60f6e06b5d5 /util/libreboot-utils
parent715723c7ceb35be1b6a592e51c70f54f3fc00bdb (diff)
util/mkhtemp: allow relative path with -p
but only -p not inside the library. that way, we retain security. symlinks resolved with use of -p; a warning will be added about this to the manpage, when written. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils')
-rw-r--r--util/libreboot-utils/mkhtemp.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/util/libreboot-utils/mkhtemp.c b/util/libreboot-utils/mkhtemp.c
index 1f7c8b79..3fa4819f 100644
--- a/util/libreboot-utils/mkhtemp.c
+++ b/util/libreboot-utils/mkhtemp.c
@@ -78,6 +78,8 @@ main(int argc, char *argv[])
int type = MKHTEMP_FILE;
size_t len;
+ char *rp;
+
#if defined (PATH_LEN) && \
(PATH_LEN) >= 256
size_t maxlen = PATH_LEN;
@@ -85,6 +87,8 @@ main(int argc, char *argv[])
size_t maxlen = 4096;
#endif
+ char resolved[maxlen];
+
if (lbgetprogname(argv[0]) == NULL)
err_no_cleanup(errno, "could not set progname");
@@ -119,6 +123,23 @@ main(int argc, char *argv[])
err_no_cleanup(EINVAL,
"usage: mkhtemp [-d] [-p dir] [template]\n");
+
+ /* user supplied -p PATH - WARNING:
+ * this permits symlinks, but only here,
+ * not in the library, so they are resolved
+ * here first, and *only here*. the mkhtemp
+ * library blocks them. be careful
+ * when using -p
+ */
+ if (tmpdir != NULL) {
+ rp = realpath(tmpdir, resolved);
+ if (rp == NULL)
+ err_no_cleanup(errno,
+ "%s", tmpdir);
+
+ tmpdir = resolved;
+ }
+
if (new_tmp_common(&fd, &s, type, tmpdir) < 0)
err_no_cleanup(errno, "%s", s);