PR#6945 and GPR#227: protect Sys and Unix functions against string arguments containing the null character '\000'
Continuation of commit dc043a7: - Update the win32unix/ files with the new checks. - Completely untested, not even compiled.master
parent
dc043a7b62
commit
9dfa69e546
|
@ -26,6 +26,7 @@ value win_create_process_native(value cmd, value cmdline, value env,
|
|||
char * exefile, * envp;
|
||||
int flags;
|
||||
|
||||
caml_unix_check_path(cmd, "create_process");
|
||||
exefile = search_exe_in_path(String_val(cmd));
|
||||
if (env != Val_int(0)) {
|
||||
envp = String_val(Field(env, 0));
|
||||
|
|
|
@ -32,6 +32,8 @@ CAMLprim value unix_link(value path1, value path2)
|
|||
(tCreateHardLink) GetProcAddress(hModKernel32, "CreateHardLinkA");
|
||||
if (pCreateHardLink == NULL)
|
||||
invalid_argument("Unix.link not implemented");
|
||||
caml_unix_check_path(path1, "link");
|
||||
caml_unix_check_path(path2, "link");
|
||||
if (! pCreateHardLink(String_val(path2), String_val(path1), NULL)) {
|
||||
win32_maperr(GetLastError());
|
||||
uerror("link", path2);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
CAMLprim value unix_mkdir(path, perm)
|
||||
value path, perm;
|
||||
{
|
||||
caml_unix_check_path(path, "mkdir");
|
||||
if (_mkdir(String_val(path)) == -1) uerror("mkdir", path);
|
||||
return Val_unit;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ CAMLprim value unix_open(value path, value flags, value perm)
|
|||
SECURITY_ATTRIBUTES attr;
|
||||
HANDLE h;
|
||||
|
||||
caml_unix_check_path(path, "open");
|
||||
fileaccess = convert_flag_list(flags, open_access_flags);
|
||||
sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE
|
||||
| convert_flag_list(flags, open_share_flags);
|
||||
|
|
|
@ -20,6 +20,8 @@ CAMLprim value unix_rename(value path1, value path2)
|
|||
static int supports_MoveFileEx = -1; /* don't know yet */
|
||||
BOOL ok;
|
||||
|
||||
caml_unix_check_path(path1, "rename");
|
||||
caml_unix_check_path(path2, "rename");
|
||||
if (supports_MoveFileEx < 0) {
|
||||
OSVERSIONINFO VersionInfo;
|
||||
VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
|
|
|
@ -66,6 +66,7 @@ CAMLprim value unix_stat(value path)
|
|||
int ret;
|
||||
struct _stati64 buf;
|
||||
|
||||
caml_unix_check_path(path, "stat");
|
||||
ret = _stati64(String_val(path), &buf);
|
||||
if (ret == -1) uerror("stat", path);
|
||||
if (buf.st_size > Max_long) {
|
||||
|
@ -79,6 +80,8 @@ CAMLprim value unix_stat_64(value path)
|
|||
{
|
||||
int ret;
|
||||
struct _stati64 buf;
|
||||
|
||||
caml_unix_check_path(path, "stat");
|
||||
ret = _stati64(String_val(path), &buf);
|
||||
if (ret == -1) uerror("stat", path);
|
||||
return stat_aux(1, &buf);
|
||||
|
|
|
@ -27,6 +27,7 @@ CAMLprim value win_system(cmd)
|
|||
char *buf;
|
||||
intnat len;
|
||||
|
||||
caml_unix_check_path(cmd, "system");
|
||||
len = caml_string_length (cmd);
|
||||
buf = caml_stat_alloc (len + 1);
|
||||
memmove (buf, String_val (cmd), len + 1);
|
||||
|
|
|
@ -303,9 +303,12 @@ void unix_error(int errcode, char *cmdname, value cmdarg)
|
|||
mlraise(res);
|
||||
}
|
||||
|
||||
void uerror(cmdname, cmdarg)
|
||||
char * cmdname;
|
||||
value cmdarg;
|
||||
void uerror(char * cmdname, value cmdarg)
|
||||
{
|
||||
unix_error(errno, cmdname, cmdarg);
|
||||
}
|
||||
|
||||
void caml_unix_check_path(value path, char * cmdname)
|
||||
{
|
||||
if (! caml_string_is_c_safe(path)) unix_error(ENOENT, cmdname, path);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ extern void win32_maperr(DWORD errcode);
|
|||
extern value unix_error_of_code (int errcode);
|
||||
extern void unix_error (int errcode, char * cmdname, value arg);
|
||||
extern void uerror (char * cmdname, value arg);
|
||||
extern void caml_unix_check_path(value path, char * cmdname);
|
||||
extern value unix_freeze_buffer (value);
|
||||
extern char ** cstringvect(value arg);
|
||||
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
#include <caml/fail.h>
|
||||
#include "unixsupport.h"
|
||||
|
||||
CAMLprim value win_findfirst(name)
|
||||
value name;
|
||||
CAMLprim value win_findfirst(value name)
|
||||
{
|
||||
HANDLE h;
|
||||
value v;
|
||||
|
@ -27,6 +26,7 @@ CAMLprim value win_findfirst(name)
|
|||
value valname = Val_unit;
|
||||
value valh = Val_unit;
|
||||
|
||||
caml_unix_check_path(name, "opendir");
|
||||
Begin_roots2 (valname,valh);
|
||||
h = FindFirstFile(String_val(name),&fileinfo);
|
||||
if (h == INVALID_HANDLE_VALUE) {
|
||||
|
@ -47,8 +47,7 @@ CAMLprim value win_findfirst(name)
|
|||
return v;
|
||||
}
|
||||
|
||||
CAMLprim value win_findnext(valh)
|
||||
value valh;
|
||||
CAMLprim value win_findnext(value valh)
|
||||
{
|
||||
WIN32_FIND_DATA fileinfo;
|
||||
BOOL retcode;
|
||||
|
@ -66,8 +65,7 @@ CAMLprim value win_findnext(valh)
|
|||
return copy_string(fileinfo.cFileName);
|
||||
}
|
||||
|
||||
CAMLprim value win_findclose(valh)
|
||||
value valh;
|
||||
CAMLprim value win_findclose(value valh)
|
||||
{
|
||||
if (! FindClose(Handle_val(valh))) {
|
||||
win32_maperr(GetLastError());
|
||||
|
|
Loading…
Reference in New Issue