Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in linux execveat proc call #3487

Open
yevhen-k opened this issue Apr 26, 2024 · 0 comments · May be fixed by #3476
Open

Bug in linux execveat proc call #3487

yevhen-k opened this issue Apr 26, 2024 · 0 comments · May be fixed by #3476

Comments

@yevhen-k
Copy link

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Operating System & Odin Version:
$ uname -svprio
Linux 6.6.26-1-MANJARO #1 SMP PREEMPT_DYNAMIC Wed Apr 10 20:11:08 UTC 2024 unknown unknown GNU/Linux

$ odin version
dev-2024-04-nightly:aab122ede
  • Please paste odin report output:
Where to find more information and get into contact when you encounter a bug:

	Website: https://odin-lang.org
	GitHub:  https://github.com/odin-lang/Odin/issues


Useful information to add to a bug report:

	Odin:    dev-2024-04-nightly:aab122ede
	OS:      Manjaro Linux, Linux 6.6.26-1-MANJARO
	CPU:     Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
	RAM:     15837 MiB
	Backend: LLVM 17.0.6

Expected Behavior

Compile and run the following code:

package execveat

import "core:fmt"
import "core:os"
import "core:sys/linux"


// odin run execveat.odin -file

main :: proc() {
	name :: "date"
	flags: linux.Open_Flags = {linux.Open_Flags_Bits.RDONLY, linux.Open_Flags.DIRECTORY}
	argv: [^]cstring
	envp: [^]cstring

	fd, fd_err := linux.open("/usr/bin", flags)
	defer linux.close(fd)

	if fd_err != .NONE {
		message := fmt.tprintf("error file desc: %d", fd_err)
		fmt.eprintfln(message)
		os.exit(-1)
	}

	err_exec := linux.execveat(fd, name, argv, envp)
	if err_exec != .NONE {
		message := fmt.tprintf("error exec: %d", err_exec)
		fmt.eprintfln(message)
		os.exit(-1)
	}

}

Expected behavior:

$ odin run execveat.odin -file            
Fri Apr 26 14:21:10 EEST 2024

Current Behavior

$ odin run execveat.odin -file            
error exec: 22

Suggestion

Add missing flags parameter to the execveat proc.

Current implementation: core/sys/linux/sys.odin#L2806-L2810 has 4 parameters, but C suggests it has to have 5 parameters:

int execveat(int dirfd, const char *pathname, char *const _Nullable argv[],
             char *const _Nullable envp[], int flags);

By manually adding missing fifth param I was able to run example with execveat call:

execveat :: proc "contextless" (dirfd: Fd, name: cstring, argv: [^]cstring, envp: [^]cstring) -> (Errno) {
	ret := syscall(SYS_execveat, dirfd, cast(rawptr) name, cast(rawptr) argv, cast(rawptr) envp, cast(rawptr)nil)
	return Errno(-ret)
}
@PucklaJ PucklaJ linked a pull request Apr 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant