From e7254ca708f97708916b9f702f435ad6b0e68a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Thu, 1 Dec 2016 14:33:23 +0100 Subject: [PATCH] Fix call to `realpath` in `posix.c` --- src/platform/posix.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/platform/posix.c b/src/platform/posix.c index ae976c4a4a..1e0e2912e8 100644 --- a/src/platform/posix.c +++ b/src/platform/posix.c @@ -699,9 +699,16 @@ void platform_get_openrct_data_path(utf8 *outPath, size_t outSize) void platform_resolve_openrct_data_path() { if (gCustomOpenrctDataPath[0] != 0) { - if (realpath(gCustomOpenrctDataPath, _openrctDataDirectoryPath) == NULL) { + // NOTE: second argument to `realpath` is meant to either be NULL or `PATH_MAX`-sized buffer, + // since our `MAX_PATH` macro is set to some other value, pass NULL to have `realpath` return + // a `malloc`ed buffer. + char *resolved_path = realpath(gCustomOpenrctDataPath, NULL); + if (resolved_path == NULL) { log_error("Could not resolve path \"%s\", errno = %d", gCustomOpenrctDataPath, errno); return; + } else { + safe_strcpy(_openrctDataDirectoryPath, resolved_path, MAX_PATH); + free(resolved_path); } path_end_with_separator(_openrctDataDirectoryPath, MAX_PATH);