Skip to content

Commit f2e32f0

Browse files
authored
file_path: avoid fortified realpath() buffer size abort (#19037)
glibc's fortified realpath() checks that the destination buffer is at least PATH_MAX bytes. path_resolve_realpath() was passing the caller's buffer directly, which may be smaller than the system PATH_MAX despite being sized to RetroArch's PATH_MAX_LENGTH. With _FORTIFY_SOURCE=3 this can abort in __realpath_chk when resolving core updater paths. Resolve into an allocated realpath() buffer instead, then copy the result back into the caller-provided buffer using the provided length.
1 parent 6b6e4d3 commit f2e32f0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

libretro-common/file/file_path.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,16 @@ char *path_resolve_realpath(char *s, size_t len, bool resolve_symlinks)
793793
const char *buf_end;
794794
if (resolve_symlinks)
795795
{
796+
char *real_path;
796797
strlcpy(tmp, s, sizeof(tmp));
797-
if (!realpath(tmp, s))
798+
real_path = realpath(tmp, NULL);
799+
if (!real_path)
798800
{
799801
strlcpy(s, tmp, len);
800802
return NULL;
801803
}
804+
strlcpy(s, real_path, len);
805+
free(real_path);
802806
return s;
803807
}
804808
t = 0;

0 commit comments

Comments
 (0)