diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-29 10:32:12 +0100 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-29 10:35:33 +0100 |
| commit | cec3de5c9eacb92e45fcd4ff88998d9b35e38663 (patch) | |
| tree | e912416b5778f594fc575079d746b6e9defd7df1 /util/libreboot-utils/lib/mkhtemp.c | |
| parent | 1539aff30236b0302c92df2c1d2b635d58f08812 (diff) | |
mkhtemp: generalised string concatenation
scatn in strings.c was buggy, so i replaced it; it
concatenates any number of things.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils/lib/mkhtemp.c')
| -rw-r--r-- | util/libreboot-utils/lib/mkhtemp.c | 15 |
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; |
