summaryrefslogtreecommitdiff
path: root/otherlibs
diff options
context:
space:
mode:
authorMarc Lasson <marc.lasson@lexifi.com>2022-11-21 09:00:56 +0100
committerGitHub <noreply@github.com>2022-11-21 09:00:56 +0100
commit3d8fb96281c94d31299859e7a72b90ce0976254c (patch)
treebbfe751e042a33dcc66a99dd0a29b71927822024 /otherlibs
parent5360277c51c33847789f05121e6d8272f27ef0e6 (diff)
downloadocaml-3d8fb96281c94d31299859e7a72b90ce0976254c.tar.gz
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.
Diffstat (limited to 'otherlibs')
-rw-r--r--otherlibs/unix/stat_win32.c12
1 files changed, 8 insertions, 4 deletions
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)