diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2015-11-15 15:13:30 +0100 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2015-11-15 15:13:30 +0100 |
commit | 9893e265d8791eea2f9c03055ef5c398296371aa (patch) | |
tree | 8d00ed2202104201195f628fd23a91e75670cce2 | |
parent | dc2a98c3a5753ac45bd9de0f994fa07f0ddc13dc (diff) | |
download | ocaml-9893e265d8791eea2f9c03055ef5c398296371aa.tar.gz |
PR#6945 and GPR#227: protect Sys and Unix functions against string arguments containing the null character '\000'
Continuation of commit dc043a7. The following otherlibs/unix/ functions were not protected:
unix_inet_of_string
unix_getgrnam
unix_getpwnam
unix_initgroups
unix_readlink
unix_utimes
-rw-r--r-- | otherlibs/unix/addrofstr.c | 9 | ||||
-rw-r--r-- | otherlibs/unix/getgr.c | 1 | ||||
-rw-r--r-- | otherlibs/unix/getpw.c | 1 | ||||
-rw-r--r-- | otherlibs/unix/initgroups.c | 3 | ||||
-rw-r--r-- | otherlibs/unix/readlink.c | 1 | ||||
-rw-r--r-- | otherlibs/unix/utimes.c | 7 |
6 files changed, 20 insertions, 2 deletions
diff --git a/otherlibs/unix/addrofstr.c b/otherlibs/unix/addrofstr.c index 207e1cd990..38161bac90 100644 --- a/otherlibs/unix/addrofstr.c +++ b/otherlibs/unix/addrofstr.c @@ -22,8 +22,10 @@ CAMLprim value unix_inet_addr_of_string(value s) { + if (! caml_string_is_c_safe(s)) failwith("inet_addr_of_string"); #if defined(HAS_IPV6) #ifdef _WIN32 + { CAMLparam1(s); CAMLlocal1(vres); struct addrinfo hints; @@ -55,7 +57,9 @@ CAMLprim value unix_inet_addr_of_string(value s) } freeaddrinfo(res); CAMLreturn (vres); + } #else + { struct in_addr address; struct in6_addr address6; if (inet_pton(AF_INET, String_val(s), &address) > 0) @@ -64,17 +68,22 @@ CAMLprim value unix_inet_addr_of_string(value s) return alloc_inet6_addr(&address6); else failwith("inet_addr_of_string"); + } #endif #elif defined(HAS_INET_ATON) + { struct in_addr address; if (inet_aton(String_val(s), &address) == 0) failwith("inet_addr_of_string"); return alloc_inet_addr(&address); + } #else + { struct in_addr address; address.s_addr = inet_addr(String_val(s)); if (address.s_addr == (uint32_t) -1) failwith("inet_addr_of_string"); return alloc_inet_addr(&address); + } #endif } diff --git a/otherlibs/unix/getgr.c b/otherlibs/unix/getgr.c index 14338ccffc..988d19d763 100644 --- a/otherlibs/unix/getgr.c +++ b/otherlibs/unix/getgr.c @@ -40,6 +40,7 @@ static value alloc_group_entry(struct group *entry) CAMLprim value unix_getgrnam(value name) { struct group * entry; + if (! caml_string_is_c_safe(name)) raise_not_found(); entry = getgrnam(String_val(name)); if (entry == NULL) raise_not_found(); return alloc_group_entry(entry); diff --git a/otherlibs/unix/getpw.c b/otherlibs/unix/getpw.c index 82fb4d8fdf..e8f4dabc00 100644 --- a/otherlibs/unix/getpw.c +++ b/otherlibs/unix/getpw.c @@ -49,6 +49,7 @@ static value alloc_passwd_entry(struct passwd *entry) CAMLprim value unix_getpwnam(value name) { struct passwd * entry; + if (! caml_string_is_c_safe(name)) raise_not_found(); entry = getpwnam(String_val(name)); if (entry == (struct passwd *) NULL) raise_not_found(); return alloc_passwd_entry(entry); diff --git a/otherlibs/unix/initgroups.c b/otherlibs/unix/initgroups.c index ca3ed4c99e..4b5e9b221f 100644 --- a/otherlibs/unix/initgroups.c +++ b/otherlibs/unix/initgroups.c @@ -21,12 +21,15 @@ #ifdef HAS_UNISTD #include <unistd.h> #endif +#include <errno.h> #include <limits.h> #include <grp.h> #include "unixsupport.h" CAMLprim value unix_initgroups(value user, value group) { + if (! caml_string_is_c_safe(user)) + unix_error(EINVAL, "initgroups", user); if (initgroups(String_val(user), Int_val(group)) == -1) { uerror("initgroups", Nothing); } diff --git a/otherlibs/unix/readlink.c b/otherlibs/unix/readlink.c index 836718d1dc..4d6401766a 100644 --- a/otherlibs/unix/readlink.c +++ b/otherlibs/unix/readlink.c @@ -36,6 +36,7 @@ CAMLprim value unix_readlink(value path) char buffer[PATH_MAX]; int len; char * p; + caml_unix_check_path(path, "readlink"); p = caml_strdup(String_val(path)); caml_enter_blocking_section(); len = readlink(p, buffer, sizeof(buffer) - 1); diff --git a/otherlibs/unix/utimes.c b/otherlibs/unix/utimes.c index bf2ae2fb26..c9a4bfca49 100644 --- a/otherlibs/unix/utimes.c +++ b/otherlibs/unix/utimes.c @@ -32,6 +32,7 @@ CAMLprim value unix_utimes(value path, value atime, value mtime) struct utimbuf times, * t; char * p; int ret; + caml_unix_check_path(path, "utimes"); times.actime = Double_val(atime); times.modtime = Double_val(mtime); if (times.actime || times.modtime) @@ -60,8 +61,10 @@ CAMLprim value unix_utimes(value path, value atime, value mtime) struct timeval tv[2], * t; char * p; int ret; - double at = Double_val(atime); - double mt = Double_val(mtime); + double at, mt; + caml_unix_check_path(path, "utimes"); + at = Double_val(atime); + mt = Double_val(mtime); tv[0].tv_sec = at; tv[0].tv_usec = (at - tv[0].tv_sec) * 1000000; tv[1].tv_sec = mt; |