diff options
author | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2023-04-27 09:31:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 09:31:39 +0200 |
commit | f11f82f18993f969be5cf5bc4a0c133a053949cb (patch) | |
tree | 8e460a7fe48ac531c71ff3834c2c1ac0442a891c /runtime/win32.c | |
parent | 8c1013322a15c09c9253eec8022fd94e366bb4de (diff) | |
download | ocaml-f11f82f18993f969be5cf5bc4a0c133a053949cb.tar.gz |
Introduce and use `caml_ext_table_add_noexc` (#12202)
Same functionality as `caml_ext_table_add`, but returns -1 when running
out of memory instead of raising an exception.
Use the new function in `caml_read_directory`, which must not raise exceptions
since it is called from blocking sections. Instead, `caml_read_directory`
returns an error code if `caml_ext_table_add_noexc` runs out of memory.
Also: harden `caml_ext_table_add{,_noexc}` against integer overflow
when computing the new table size for resizing.
Fixes: #10403
Diffstat (limited to 'runtime/win32.c')
-rw-r--r-- | runtime/win32.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/runtime/win32.c b/runtime/win32.c index 70c90f7a11..599805145f 100644 --- a/runtime/win32.c +++ b/runtime/win32.c @@ -445,7 +445,9 @@ CAMLexport int caml_read_directory(wchar_t * dirname, } do { if (wcscmp(fileinfo.name, L".") != 0 && wcscmp(fileinfo.name, L"..") != 0) { - caml_ext_table_add(contents, caml_stat_strdup_of_utf16(fileinfo.name)); + res = caml_ext_table_add_noexc(contents, + caml_stat_strdup_of_utf16(fileinfo.name)); + if (res == -1) { _findclose(h); errno = ENOMEM; return -1; } } } while (_wfindnext(h, &fileinfo) == 0); _findclose(h); |