From 3d8fb96281c94d31299859e7a72b90ce0976254c Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Mon, 21 Nov 2022 09:00:56 +0100 Subject: Missing CAMLparam in win32's Unix.stat (#11737) The `path` argument is used after a `caml_enter_blocking_section` when the path does not exists (the path is used to build the unix error exception). Unfortunately, during the blocking section we may "yield" to a thread that can trigger a garbage collection and move the content of `path` elsewhere, triggering a segfault. The CAMLparam is therefore needed in that case. --- otherlibs/unix/stat_win32.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'otherlibs') diff --git a/otherlibs/unix/stat_win32.c b/otherlibs/unix/stat_win32.c index ac717bc2b3..197e4340d6 100644 --- a/otherlibs/unix/stat_win32.c +++ b/otherlibs/unix/stat_win32.c @@ -339,6 +339,7 @@ static int do_stat(int do_lstat, int use_64, const char* opath, HANDLE fstat, __ CAMLprim value caml_unix_stat(value path) { + CAMLparam1(path); struct _stat64 buf; __int64 st_ino; @@ -346,11 +347,12 @@ CAMLprim value caml_unix_stat(value path) if (!do_stat(0, 0, String_val(path), NULL, &st_ino, &buf)) { caml_uerror("stat", path); } - return stat_aux(0, st_ino, &buf); + CAMLreturn (stat_aux(0, st_ino, &buf)); } CAMLprim value caml_unix_stat_64(value path) { + CAMLparam1(path); struct _stat64 buf; __int64 st_ino; @@ -358,11 +360,12 @@ CAMLprim value caml_unix_stat_64(value path) if (!do_stat(0, 1, String_val(path), NULL, &st_ino, &buf)) { caml_uerror("stat", path); } - return stat_aux(1, st_ino, &buf); + CAMLreturn (stat_aux(1, st_ino, &buf)); } CAMLprim value caml_unix_lstat(value path) { + CAMLparam1(path); struct _stat64 buf; __int64 st_ino; @@ -370,11 +373,12 @@ CAMLprim value caml_unix_lstat(value path) if (!do_stat(1, 0, String_val(path), NULL, &st_ino, &buf)) { caml_uerror("lstat", path); } - return stat_aux(0, st_ino, &buf); + CAMLreturn (stat_aux(0, st_ino, &buf)); } CAMLprim value caml_unix_lstat_64(value path) { + CAMLparam1(path); struct _stat64 buf; __int64 st_ino; @@ -382,7 +386,7 @@ CAMLprim value caml_unix_lstat_64(value path) if (!do_stat(1, 1, String_val(path), NULL, &st_ino, &buf)) { caml_uerror("lstat", path); } - return stat_aux(1, st_ino, &buf); + CAMLreturn (stat_aux(1, st_ino, &buf)); } static value do_fstat(value handle, int use_64) -- cgit v1.2.1