From f249c73178b645272fa7592186ad381dead16f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arma=C3=ABl=20Gu=C3=A9neau?= Date: Wed, 10 Oct 2018 12:00:51 +0200 Subject: Fix Unix.getaddrinfo when called on strings containing null bytes --- Changes | 4 ++++ otherlibs/unix/getaddrinfo.c | 2 +- testsuite/tests/lib-unix/common/getaddrinfo.ml | 13 +++++++++++++ testsuite/tests/lib-unix/common/ocamltests | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/lib-unix/common/getaddrinfo.ml 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 -- cgit v1.2.1