Skip to content

Commit 6729eb8

Browse files
mlassonnojb
authored andcommitted
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. (cherry picked from commit 3d8fb96)
1 parent fb5b1e4 commit 6729eb8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Changes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ OCaml 4.14 maintenance branch
6464
mismatch error involving recursive types.
6565
(Florian Angeletti, review by Gabriel Scherer)
6666

67+
- #11737: Fix segfault condition in Unix.stat under Windows in the presence of
68+
multiple threads.
69+
(Marc Lasson, Nicolás Ojeda Bär, review by Gabriel Scherer and David Allsopp)
70+
6771
OCaml 4.14.0 (28 March 2022)
6872
----------------------------
6973

otherlibs/win32unix/stat.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,50 +347,54 @@ static int do_stat(int do_lstat, int use_64, const char* opath, HANDLE fstat, __
347347

348348
CAMLprim value unix_stat(value path)
349349
{
350+
CAMLparam1(path);
350351
struct _stat64 buf;
351352
__int64 st_ino;
352353

353354
caml_unix_check_path(path, "stat");
354355
if (!do_stat(0, 0, String_val(path), NULL, &st_ino, &buf)) {
355356
uerror("stat", path);
356357
}
357-
return stat_aux(0, st_ino, &buf);
358+
CAMLreturn (stat_aux(0, st_ino, &buf));
358359
}
359360

360361
CAMLprim value unix_stat_64(value path)
361362
{
363+
CAMLparam1(path);
362364
struct _stat64 buf;
363365
__int64 st_ino;
364366

365367
caml_unix_check_path(path, "stat");
366368
if (!do_stat(0, 1, String_val(path), NULL, &st_ino, &buf)) {
367369
uerror("stat", path);
368370
}
369-
return stat_aux(1, st_ino, &buf);
371+
CAMLreturn (stat_aux(1, st_ino, &buf));
370372
}
371373

372374
CAMLprim value unix_lstat(value path)
373375
{
376+
CAMLparam1(path);
374377
struct _stat64 buf;
375378
__int64 st_ino;
376379

377380
caml_unix_check_path(path, "lstat");
378381
if (!do_stat(1, 0, String_val(path), NULL, &st_ino, &buf)) {
379382
uerror("lstat", path);
380383
}
381-
return stat_aux(0, st_ino, &buf);
384+
CAMLreturn (stat_aux(0, st_ino, &buf));
382385
}
383386

384387
CAMLprim value unix_lstat_64(value path)
385388
{
389+
CAMLparam1(path);
386390
struct _stat64 buf;
387391
__int64 st_ino;
388392

389393
caml_unix_check_path(path, "lstat");
390394
if (!do_stat(1, 1, String_val(path), NULL, &st_ino, &buf)) {
391395
uerror("lstat", path);
392396
}
393-
return stat_aux(1, st_ino, &buf);
397+
CAMLreturn (stat_aux(1, st_ino, &buf));
394398
}
395399

396400
static value do_fstat(value handle, int use_64)

0 commit comments

Comments
 (0)