summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/mkhtemp.c
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-31 07:42:40 +0100
committerLeah Rowe <leah@libreboot.org>2026-03-31 07:42:40 +0100
commit2f7623ff06ca9b1b77c65ab7ba3acfe7ccf371d8 (patch)
tree685c63a6302898acb6b5b1407ec28e1662985bcb /util/libreboot-utils/mkhtemp.c
parentfb5f1b4ed150087ee22c4ce9864fa9cd04178a9f (diff)
libreboot-utils: unified max path lengths
just use PATH_MAX like a normal person with additional safety Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils/mkhtemp.c')
-rw-r--r--util/libreboot-utils/mkhtemp.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/util/libreboot-utils/mkhtemp.c b/util/libreboot-utils/mkhtemp.c
index f4c2b646..f7480ed6 100644
--- a/util/libreboot-utils/mkhtemp.c
+++ b/util/libreboot-utils/mkhtemp.c
@@ -40,12 +40,6 @@ exit_cleanup(void);
int
main(int argc, char *argv[])
{
-#if defined (PATH_LEN) && \
- (PATH_LEN) >= 256
- size_t maxlen = PATH_LEN;
-#else
- size_t maxlen = 4096;
-#endif
size_t len;
size_t tlen;
size_t xc = 0;
@@ -55,7 +49,7 @@ main(int argc, char *argv[])
char *p;
char *s = NULL;
char *rp;
- char resolved[maxlen];
+ char resolved[PATH_MAX];
char c;
int fd = -1;
@@ -95,7 +89,7 @@ main(int argc, char *argv[])
/* custom template e.g. foo.XXXXXXXXXXXXXXXXXXXXX */
if (template != NULL) {
- for (p = template + slen(template, maxlen, &tlen);
+ for (p = template + slen(template, PATH_MAX, &tlen);
p > template && *--p == 'X'; xc++);
if (xc < 3) /* the gnu mktemp errs on less than 3 */
@@ -129,8 +123,8 @@ main(int argc, char *argv[])
if (*s == '\0')
err_exit(EFAULT, "empty string initialisation");
- slen(s, maxlen, &len); /* Nullterminierung prüfen */
- /* for good measure */
+ slen(s, PATH_MAX, &len); /* Nullterminierung prüfen */
+ /* for good measure. (bonus: also re-checks length overflow) */
printf("%s\n", s);