diff options
author | Armaël Guéneau <armael.gueneau@ens-lyon.fr> | 2018-10-10 12:00:51 +0200 |
---|---|---|
committer | Armaël Guéneau <armael.gueneau@ens-lyon.fr> | 2018-10-10 19:24:21 +0200 |
commit | f249c73178b645272fa7592186ad381dead16f62 (patch) | |
tree | 6c5e4e64f201bfc30a97094eaf1a7b3ff6a9b908 | |
parent | 63dbb11d4ddf72d7b143678790d20c4d1b2001e4 (diff) | |
download | ocaml-f249c73178b645272fa7592186ad381dead16f62.tar.gz |
Fix Unix.getaddrinfo when called on strings containing null bytes
-rw-r--r-- | Changes | 4 | ||||
-rw-r--r-- | otherlibs/unix/getaddrinfo.c | 2 | ||||
-rw-r--r-- | testsuite/tests/lib-unix/common/getaddrinfo.ml | 13 | ||||
-rw-r--r-- | testsuite/tests/lib-unix/common/ocamltests | 1 |
4 files changed, 19 insertions, 1 deletions
@@ -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 |