mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
posix: remove the is_temp things that prevented use-after-frees
https://github.com/odin-lang/Odin/commit/d0709a7de21efded4625167dbff4a7dd13d561b4 fixes those another way.
This commit is contained in:
@@ -12,7 +12,7 @@ _lookup_env :: proc(key: string, allocator: runtime.Allocator) -> (value: string
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
ckey := strings.clone_to_cstring(key, temp_allocator())
|
ckey := strings.clone_to_cstring(key, temp_allocator())
|
||||||
cval := posix.getenv(ckey)
|
cval := posix.getenv(ckey)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ _lookup_env :: proc(key: string, allocator: runtime.Allocator) -> (value: string
|
|||||||
if key == "" {
|
if key == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
wkey, _ := win32_utf8_to_wstring(key, temp_allocator())
|
wkey, _ := win32_utf8_to_wstring(key, temp_allocator())
|
||||||
|
|
||||||
n := win32.GetEnvironmentVariableW(wkey, nil, 0)
|
n := win32.GetEnvironmentVariableW(wkey, nil, 0)
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ _read_link_cstr :: proc(name_cstr: cstring, allocator: runtime.Allocator) -> (st
|
|||||||
}
|
}
|
||||||
|
|
||||||
_read_link :: proc(name: string, allocator: runtime.Allocator) -> (s: string, e: Error) {
|
_read_link :: proc(name: string, allocator: runtime.Allocator) -> (s: string, e: Error) {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
name_cstr := temp_cstring(name) or_return
|
name_cstr := temp_cstring(name) or_return
|
||||||
return _read_link_cstr(name_cstr, allocator)
|
return _read_link_cstr(name_cstr, allocator)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ _symlink :: proc(old_name, new_name: string) -> Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_read_link :: proc(name: string, allocator: runtime.Allocator) -> (s: string, err: Error) {
|
_read_link :: proc(name: string, allocator: runtime.Allocator) -> (s: string, err: Error) {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
cname := temp_cstring(name)
|
cname := temp_cstring(name)
|
||||||
|
|
||||||
buf: [dynamic]byte
|
buf: [dynamic]byte
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import "base:runtime"
|
|||||||
import "core:sys/posix"
|
import "core:sys/posix"
|
||||||
|
|
||||||
_posix_absolute_path :: proc(fd: posix.FD, name: string, allocator: runtime.Allocator) -> (path: cstring, err: Error) {
|
_posix_absolute_path :: proc(fd: posix.FD, name: string, allocator: runtime.Allocator) -> (path: cstring, err: Error) {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
cname := temp_cstring(name)
|
cname := temp_cstring(name)
|
||||||
|
|
||||||
buf: [posix.PATH_MAX]byte
|
buf: [posix.PATH_MAX]byte
|
||||||
|
|||||||
@@ -609,7 +609,7 @@ _normalize_link_path :: proc(p: []u16, allocator: runtime.Allocator) -> (str: st
|
|||||||
return "", _get_platform_error()
|
return "", _get_platform_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
buf := make([]u16, n+1, temp_allocator())
|
buf := make([]u16, n+1, temp_allocator())
|
||||||
n = win32.GetFinalPathNameByHandleW(handle, raw_data(buf), u32(len(buf)), win32.VOLUME_NAME_DOS)
|
n = win32.GetFinalPathNameByHandleW(handle, raw_data(buf), u32(len(buf)), win32.VOLUME_NAME_DOS)
|
||||||
@@ -635,7 +635,7 @@ _read_link :: proc(name: string, allocator: runtime.Allocator) -> (s: string, er
|
|||||||
@thread_local
|
@thread_local
|
||||||
rdb_buf: [MAXIMUM_REPARSE_DATA_BUFFER_SIZE]byte
|
rdb_buf: [MAXIMUM_REPARSE_DATA_BUFFER_SIZE]byte
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
p := _fix_long_path(name, temp_allocator()) or_return
|
p := _fix_long_path(name, temp_allocator()) or_return
|
||||||
handle := _open_sym_link(p) or_return
|
handle := _open_sym_link(p) or_return
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ _remove_all :: proc(path: string) -> Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_get_working_directory :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
_get_working_directory :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
buf: [dynamic]byte
|
buf: [dynamic]byte
|
||||||
buf.allocator = temp_allocator()
|
buf.allocator = temp_allocator()
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ _remove_all :: proc(path: string) -> Error {
|
|||||||
_get_working_directory :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
_get_working_directory :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||||
win32.AcquireSRWLockExclusive(&cwd_lock)
|
win32.AcquireSRWLockExclusive(&cwd_lock)
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
sz_utf16 := win32.GetCurrentDirectoryW(0, nil)
|
sz_utf16 := win32.GetCurrentDirectoryW(0, nil)
|
||||||
dir_buf_wstr := make([]u16, sz_utf16, temp_allocator()) or_return
|
dir_buf_wstr := make([]u16, sz_utf16, temp_allocator()) or_return
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ _process_list :: proc(allocator: runtime.Allocator) -> (list: []int, err: Error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
buffer := make([]i32, ret, temp_allocator())
|
buffer := make([]i32, ret, temp_allocator())
|
||||||
ret = darwin.proc_listallpids(raw_data(buffer), ret*size_of(i32))
|
ret = darwin.proc_listallpids(raw_data(buffer), ret*size_of(i32))
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|||||||
_ = read_memory_as_struct(ph, process_peb.ProcessParameters, &process_params) or_return
|
_ = read_memory_as_struct(ph, process_peb.ProcessParameters, &process_params) or_return
|
||||||
|
|
||||||
if selection >= {.Command_Line, .Command_Args} {
|
if selection >= {.Command_Line, .Command_Args} {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
cmdline_w := make([]u16, process_params.CommandLine.Length, temp_allocator()) or_return
|
cmdline_w := make([]u16, process_params.CommandLine.Length, temp_allocator()) or_return
|
||||||
_ = read_memory_as_slice(ph, process_params.CommandLine.Buffer, cmdline_w) or_return
|
_ = read_memory_as_slice(ph, process_params.CommandLine.Buffer, cmdline_w) or_return
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if .Environment in selection {
|
if .Environment in selection {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
env_len := process_params.EnvironmentSize / 2
|
env_len := process_params.EnvironmentSize / 2
|
||||||
envs_w := make([]u16, env_len, temp_allocator()) or_return
|
envs_w := make([]u16, env_len, temp_allocator()) or_return
|
||||||
_ = read_memory_as_slice(ph, process_params.Environment, envs_w) or_return
|
_ = read_memory_as_slice(ph, process_params.Environment, envs_w) or_return
|
||||||
@@ -181,7 +181,7 @@ _process_info_by_pid :: proc(pid: int, selection: Process_Info_Fields, allocator
|
|||||||
info.fields += {.Environment}
|
info.fields += {.Environment}
|
||||||
}
|
}
|
||||||
if .Working_Dir in selection {
|
if .Working_Dir in selection {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
cwd_w := make([]u16, process_params.CurrentDirectoryPath.Length, temp_allocator()) or_return
|
cwd_w := make([]u16, process_params.CurrentDirectoryPath.Length, temp_allocator()) or_return
|
||||||
_ = read_memory_as_slice(ph, process_params.CurrentDirectoryPath.Buffer, cwd_w) or_return
|
_ = read_memory_as_slice(ph, process_params.CurrentDirectoryPath.Buffer, cwd_w) or_return
|
||||||
|
|
||||||
@@ -250,7 +250,7 @@ _process_info_by_handle :: proc(process: Process, selection: Process_Info_Fields
|
|||||||
_ = read_memory_as_struct(ph, process_peb.ProcessParameters, &process_params) or_return
|
_ = read_memory_as_struct(ph, process_peb.ProcessParameters, &process_params) or_return
|
||||||
|
|
||||||
if selection >= {.Command_Line, .Command_Args} {
|
if selection >= {.Command_Line, .Command_Args} {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
cmdline_w := make([]u16, process_params.CommandLine.Length, temp_allocator()) or_return
|
cmdline_w := make([]u16, process_params.CommandLine.Length, temp_allocator()) or_return
|
||||||
_ = read_memory_as_slice(ph, process_params.CommandLine.Buffer, cmdline_w) or_return
|
_ = read_memory_as_slice(ph, process_params.CommandLine.Buffer, cmdline_w) or_return
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ _process_info_by_handle :: proc(process: Process, selection: Process_Info_Fields
|
|||||||
}
|
}
|
||||||
|
|
||||||
if .Environment in selection {
|
if .Environment in selection {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
env_len := process_params.EnvironmentSize / 2
|
env_len := process_params.EnvironmentSize / 2
|
||||||
envs_w := make([]u16, env_len, temp_allocator()) or_return
|
envs_w := make([]u16, env_len, temp_allocator()) or_return
|
||||||
_ = read_memory_as_slice(ph, process_params.Environment, envs_w) or_return
|
_ = read_memory_as_slice(ph, process_params.Environment, envs_w) or_return
|
||||||
@@ -275,7 +275,7 @@ _process_info_by_handle :: proc(process: Process, selection: Process_Info_Fields
|
|||||||
}
|
}
|
||||||
|
|
||||||
if .Working_Dir in selection {
|
if .Working_Dir in selection {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
cwd_w := make([]u16, process_params.CurrentDirectoryPath.Length, temp_allocator()) or_return
|
cwd_w := make([]u16, process_params.CurrentDirectoryPath.Length, temp_allocator()) or_return
|
||||||
_ = read_memory_as_slice(ph, process_params.CurrentDirectoryPath.Buffer, cwd_w) or_return
|
_ = read_memory_as_slice(ph, process_params.CurrentDirectoryPath.Buffer, cwd_w) or_return
|
||||||
|
|
||||||
@@ -539,7 +539,7 @@ _process_exe_by_pid :: proc(pid: int, allocator: runtime.Allocator) -> (exe_path
|
|||||||
}
|
}
|
||||||
|
|
||||||
_get_process_user :: proc(process_handle: win32.HANDLE, allocator: runtime.Allocator) -> (full_username: string, err: Error) {
|
_get_process_user :: proc(process_handle: win32.HANDLE, allocator: runtime.Allocator) -> (full_username: string, err: Error) {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
token_handle: win32.HANDLE
|
token_handle: win32.HANDLE
|
||||||
if !win32.OpenProcessToken(process_handle, win32.TOKEN_QUERY, &token_handle) {
|
if !win32.OpenProcessToken(process_handle, win32.TOKEN_QUERY, &token_handle) {
|
||||||
err = _get_platform_error()
|
err = _get_platform_error()
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ _fstat_internal :: proc(fd: linux.Fd, allocator: runtime.Allocator) -> (fi: File
|
|||||||
|
|
||||||
// NOTE: _stat and _lstat are using _fstat to avoid a race condition when populating fullpath
|
// NOTE: _stat and _lstat are using _fstat to avoid a race condition when populating fullpath
|
||||||
_stat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, err: Error) {
|
_stat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, err: Error) {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
name_cstr := temp_cstring(name) or_return
|
name_cstr := temp_cstring(name) or_return
|
||||||
|
|
||||||
fd, errno := linux.open(name_cstr, {})
|
fd, errno := linux.open(name_cstr, {})
|
||||||
@@ -60,7 +60,7 @@ _stat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
_lstat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, err: Error) {
|
_lstat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, err: Error) {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
name_cstr := temp_cstring(name) or_return
|
name_cstr := temp_cstring(name) or_return
|
||||||
|
|
||||||
fd, errno := linux.open(name_cstr, {.PATH, .NOFOLLOW})
|
fd, errno := linux.open(name_cstr, {.PATH, .NOFOLLOW})
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ _stat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
cname := temp_cstring(name) or_return
|
cname := temp_cstring(name) or_return
|
||||||
|
|
||||||
fd := posix.open(cname, {})
|
fd := posix.open(cname, {})
|
||||||
@@ -97,7 +97,7 @@ _lstat :: proc(name: string, allocator: runtime.Allocator) -> (fi: File_Info, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
// NOTE: can't use realpath or open (+ fcntl F_GETPATH) here because it tries to resolve symlinks.
|
// NOTE: can't use realpath or open (+ fcntl F_GETPATH) here because it tries to resolve symlinks.
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ full_path_from_name :: proc(name: string, allocator: runtime.Allocator) -> (path
|
|||||||
name = "."
|
name = "."
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
p := win32_utf8_to_utf16(name, temp_allocator()) or_return
|
p := win32_utf8_to_utf16(name, temp_allocator()) or_return
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ internal_stat :: proc(name: string, create_file_attributes: u32, allocator: runt
|
|||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
return {}, .Not_Exist
|
return {}, .Not_Exist
|
||||||
}
|
}
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
wname := _fix_long_path(name, temp_allocator()) or_return
|
wname := _fix_long_path(name, temp_allocator()) or_return
|
||||||
fa: win32.WIN32_FILE_ATTRIBUTE_DATA
|
fa: win32.WIN32_FILE_ATTRIBUTE_DATA
|
||||||
@@ -129,7 +129,7 @@ _cleanpath_from_handle :: proc(f: ^File, allocator: runtime.Allocator) -> (strin
|
|||||||
return "", _get_platform_error()
|
return "", _get_platform_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
buf := make([]u16, max(n, 260)+1, temp_allocator())
|
buf := make([]u16, max(n, 260)+1, temp_allocator())
|
||||||
n = win32.GetFinalPathNameByHandleW(h, raw_data(buf), u32(len(buf)), 0)
|
n = win32.GetFinalPathNameByHandleW(h, raw_data(buf), u32(len(buf)), 0)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ mkdir_temp :: make_directory_temp
|
|||||||
// If `dir` is an empty tring, `temp_directory()` will be used.
|
// If `dir` is an empty tring, `temp_directory()` will be used.
|
||||||
@(require_results)
|
@(require_results)
|
||||||
make_directory_temp :: proc(dir, pattern: string, allocator: runtime.Allocator) -> (temp_path: string, err: Error) {
|
make_directory_temp :: proc(dir, pattern: string, allocator: runtime.Allocator) -> (temp_path: string, err: Error) {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
dir := dir if dir != "" else temp_directory(temp_allocator()) or_return
|
dir := dir if dir != "" else temp_directory(temp_allocator()) or_return
|
||||||
prefix, suffix := _prefix_and_suffix(pattern) or_return
|
prefix, suffix := _prefix_and_suffix(pattern) or_return
|
||||||
prefix = temp_join_path(dir, prefix) or_return
|
prefix = temp_join_path(dir, prefix) or_return
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package os2
|
|||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
|
|
||||||
_temp_dir :: proc(allocator: runtime.Allocator) -> (string, runtime.Allocator_Error) {
|
_temp_dir :: proc(allocator: runtime.Allocator) -> (string, runtime.Allocator_Error) {
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
tmpdir := get_env("TMPDIR", temp_allocator())
|
tmpdir := get_env("TMPDIR", temp_allocator())
|
||||||
if tmpdir == "" {
|
if tmpdir == "" {
|
||||||
tmpdir = "/tmp"
|
tmpdir = "/tmp"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ _temp_dir :: proc(allocator: runtime.Allocator) -> (string, runtime.Allocator_Er
|
|||||||
if n == 0 {
|
if n == 0 {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
TEMP_ALLOCATOR_GUARD(ignore=is_temp(allocator))
|
TEMP_ALLOCATOR_GUARD()
|
||||||
|
|
||||||
b := make([]u16, max(win32.MAX_PATH, n), temp_allocator())
|
b := make([]u16, max(win32.MAX_PATH, n), temp_allocator())
|
||||||
n = win32.GetTempPathW(u32(len(b)), raw_data(b))
|
n = win32.GetTempPathW(u32(len(b)), raw_data(b))
|
||||||
|
|||||||
Reference in New Issue
Block a user