cmd/ztest: avoid PATH_MAX stack allocation in ztest_get_zdb_bin() (#18085)

Calling realpath(path, buf) can trigger fortified header wrappers that
allocate a PATH_MAX-sized temporary buffer on the stack, exceeding the
4 KiB frame limit on some systems. Use the heap-allocating
realpath(path, NULL) form instead.

Sponsored-by: ERNW Research GmbH - https://ernw-research.de/

Signed-off-by: Alexander Moch <amoch@ernw.de>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
This commit is contained in:
Alexander Moch 2025-12-29 19:16:34 +00:00 committed by Tony Hutter
parent f1321648a5
commit 8e946b5ae8

View File

@ -7146,6 +7146,7 @@ static void
ztest_get_zdb_bin(char *bin, int len)
{
char *zdb_path;
char *resolved;
/*
* Try to use $ZDB and in-tree zdb path. If not successful, just
* let popen to search through PATH.
@ -7159,7 +7160,11 @@ ztest_get_zdb_bin(char *bin, int len)
return;
}
VERIFY3P(realpath(getexecname(), bin), !=, NULL);
resolved = realpath(getexecname(), NULL);
VERIFY3P(resolved, !=, NULL);
strlcpy(bin, resolved, len);
free(resolved);
if (strstr(bin, ".libs/ztest")) {
strstr(bin, ".libs/ztest")[0] = '\0'; /* In-tree */
strcat(bin, "zdb");