From 7e8a710ca33bed6cbdcb5af697f7a16d9ed66bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20B=C3=B6ving?= Date: Thu, 16 Apr 2026 14:38:17 +0200 Subject: [PATCH] fix: two bugs in io.cpp (#13427) This PR fixes two minor bugs in `io.cpp`: 1. A resource leak in a Windows error path of `Std.Time.Database.Windows.getNextTransition` 2. A buffer overrun in `IO.appPath` on linux when the executable is a symlink at max path length. --- src/runtime/io.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/io.cpp b/src/runtime/io.cpp index f37250b0df..a4cac03191 100644 --- a/src/runtime/io.cpp +++ b/src/runtime/io.cpp @@ -752,6 +752,7 @@ extern "C" LEAN_EXPORT obj_res lean_windows_get_next_transition(b_obj_arg timezo u_strToUTF8(dst_name, sizeof(dst_name), &dst_name_len, tzID, tzIDLength, &status); if (U_FAILURE(status)) { + ucal_close(cal); return lean_io_result_mk_error(lean_mk_io_error_invalid_argument(EINVAL, mk_string("failed to convert DST name to UTF-8"))); } @@ -1397,7 +1398,7 @@ extern "C" LEAN_EXPORT obj_res lean_io_app_path() { memset(dest, 0, PATH_MAX); pid_t pid = getpid(); snprintf(path, PATH_MAX, "/proc/%d/exe", pid); - if (readlink(path, dest, PATH_MAX) == -1) { + if (readlink(path, dest, PATH_MAX - 1) == -1) { return io_result_mk_error("failed to locate application"); } else { return io_result_mk_ok(mk_string(dest));