diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-10-03 05:27:36 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-10-03 05:27:36 +0000 |
commit | bd2e46c8255fad4e75e589b3286ead560e910b39 (patch) | |
tree | 4f194bdb2e9edcc69ef2ab0dfb4aab15ca259267 /libgo/go/syscall/exec_unix.go | |
parent | bed6238ce677ba18a672a58bc077cec6de47f8d3 (diff) | |
download | gcc-bd2e46c8255fad4e75e589b3286ead560e910b39.zip gcc-bd2e46c8255fad4e75e589b3286ead560e910b39.tar.gz gcc-bd2e46c8255fad4e75e589b3286ead560e910b39.tar.bz2 |
libgo: Update to Go 1.0.3.
From-SVN: r192025
Diffstat (limited to 'libgo/go/syscall/exec_unix.go')
-rw-r--r-- | libgo/go/syscall/exec_unix.go | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/libgo/go/syscall/exec_unix.go b/libgo/go/syscall/exec_unix.go index 664908d..b34ee1b 100644 --- a/libgo/go/syscall/exec_unix.go +++ b/libgo/go/syscall/exec_unix.go @@ -103,8 +103,9 @@ import ( var ForkLock sync.RWMutex -// Convert array of string to array -// of NUL-terminated byte pointer. +// Convert array of string to array of NUL-terminated byte pointer. +// If any string contains a NUL byte this function panics instead +// of returning an error. func StringSlicePtr(ss []string) []*byte { bb := make([]*byte, len(ss)+1) for i := 0; i < len(ss); i++ { @@ -114,6 +115,22 @@ func StringSlicePtr(ss []string) []*byte { return bb } +// slicePtrFromStrings converts a slice of strings to a slice of +// pointers to NUL-terminated byte slices. If any string contains +// a NUL byte, it returns (nil, EINVAL). +func slicePtrFromStrings(ss []string) ([]*byte, error) { + var err error + bb := make([]*byte, len(ss)+1) + for i := 0; i < len(ss); i++ { + bb[i], err = bytePtrFromString(ss[i]) + if err != nil { + return nil, err + } + } + bb[len(ss)] = nil + return bb, nil +} + func CloseOnExec(fd int) { fcntl(fd, F_SETFD, FD_CLOEXEC) } func SetNonblock(fd int, nonblocking bool) (err error) { @@ -168,9 +185,18 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) p[1] = -1 // Convert args to C form. - argv0p := StringBytePtr(argv0) - argvp := StringSlicePtr(argv) - envvp := StringSlicePtr(attr.Env) + argv0p, err := bytePtrFromString(argv0) + if err != nil { + return 0, err + } + argvp, err := slicePtrFromStrings(argv) + if err != nil { + return 0, err + } + envvp, err := slicePtrFromStrings(attr.Env) + if err != nil { + return 0, err + } if runtime.GOOS == "freebsd" && len(argv[0]) > len(argv0) { argvp[0] = argv0p @@ -178,11 +204,17 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) var chroot *byte if sys.Chroot != "" { - chroot = StringBytePtr(sys.Chroot) + chroot, err = bytePtrFromString(sys.Chroot) + if err != nil { + return 0, err + } } var dir *byte if attr.Dir != "" { - dir = StringBytePtr(attr.Dir) + dir, err = bytePtrFromString(attr.Dir) + if err != nil { + return 0, err + } } // Acquire the fork lock so that no other threads @@ -254,8 +286,18 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle // Ordinary exec. func Exec(argv0 string, argv []string, envv []string) (err error) { - err1 := raw_execve(StringBytePtr(argv0), - &StringSlicePtr(argv)[0], - &StringSlicePtr(envv)[0]) + argv0p, err := bytePtrFromString(argv0) + if err != nil { + return err + } + argvp, err := slicePtrFromStrings(argv) + if err != nil { + return err + } + envvp, err := slicePtrFromStrings(envv) + if err != nil { + return err + } + err1 := raw_execve(argv0p, &argvp[0], &envvp[0]) return Errno(err1) } |