summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes4
-rw-r--r--otherlibs/unix/getaddrinfo.c2
-rw-r--r--testsuite/tests/lib-unix/common/getaddrinfo.ml13
-rw-r--r--testsuite/tests/lib-unix/common/ocamltests1
4 files changed, 19 insertions, 1 deletions
diff --git a/Changes b/Changes
index 74dd8220cf..18718d1c97 100644
--- a/Changes
+++ b/Changes
@@ -434,6 +434,10 @@ Working version
### Bug fixes:
+- GPR#2100: Fix Unix.getaddrinfo when called on strings containing
+ null bytes; it would crash the GC later on.
+ (Armaël Guéneau, report and fix by Joe, review by Sébastien Hinderer)
+
- MPR#7847, GPR#2019: Fix an infinite loop that could occur when the
(Menhir-generated) parser encountered a syntax error in a certain
specific state.
diff --git a/otherlibs/unix/getaddrinfo.c b/otherlibs/unix/getaddrinfo.c
index ab605bd275..4b2cd6e3a4 100644
--- a/otherlibs/unix/getaddrinfo.c
+++ b/otherlibs/unix/getaddrinfo.c
@@ -65,7 +65,7 @@ CAMLprim value unix_getaddrinfo(value vnode, value vserv, value vopts)
int retcode;
if (! (caml_string_is_c_safe(vnode) && caml_string_is_c_safe(vserv)))
- return Val_int(0);
+ CAMLreturn (Val_int(0));
/* Extract "node" parameter */
if (caml_string_length(vnode) == 0) {
diff --git a/testsuite/tests/lib-unix/common/getaddrinfo.ml b/testsuite/tests/lib-unix/common/getaddrinfo.ml
new file mode 100644
index 0000000000..cead0d8469
--- /dev/null
+++ b/testsuite/tests/lib-unix/common/getaddrinfo.ml
@@ -0,0 +1,13 @@
+(* TEST
+include unix
+*)
+
+let () =
+ let x = Unix.getaddrinfo "\000" "" [] in
+ Gc.full_major ();
+ assert (x = []);;
+
+let () =
+ let x = Unix.getaddrinfo "" "\000" [] in
+ Gc.full_major ();
+ assert (x = []);;
diff --git a/testsuite/tests/lib-unix/common/ocamltests b/testsuite/tests/lib-unix/common/ocamltests
index 04b43c8e5c..39d6b8627e 100644
--- a/testsuite/tests/lib-unix/common/ocamltests
+++ b/testsuite/tests/lib-unix/common/ocamltests
@@ -8,3 +8,4 @@ rename.ml
test_unix_cmdline.ml
utimes.ml
wait_nohang.ml
+getaddrinfo.ml