summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/lib/mkhtemp.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/libreboot-utils/lib/mkhtemp.c')
-rw-r--r--util/libreboot-utils/lib/mkhtemp.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/util/libreboot-utils/lib/mkhtemp.c b/util/libreboot-utils/lib/mkhtemp.c
index 72942868..743a59fd 100644
--- a/util/libreboot-utils/lib/mkhtemp.c
+++ b/util/libreboot-utils/lib/mkhtemp.c
@@ -135,19 +135,12 @@ new_tmp_common(int *fd, char **path, int type,
if (slen(templatestr, maxlen, &templatestr_len) < 0)
goto err;
- /* sizeof adds an extra byte, useful
- * because we also want '.' or '/'
- */
+ /* may as well calculate in advance */
destlen = dirlen + 1 + templatestr_len;
- if (destlen > maxlen - 1) {
- errno = EOVERFLOW;
+ /* full path: */
+ if (scatn(3, (const char *[]) { tmpdir, "/", templatestr },
+ maxlen, &dest) < 0)
goto err;
- }
-
- memcpy(smalloc(&dest, destlen + 1), tmpdir, dirlen);
- *(dest + dirlen) = '/';
- memcpy(dest + dirlen + 1, templatestr, templatestr_len);
- *(dest + destlen) = '\0';
fname = dest + dirlen + 1;