!78 补充InterIO.go:RecvUntilByte,增加Utils.go:GetSubfixPath(),调整Sandbox

Merge pull request !78 from a-alpha/alpha-dev
This commit is contained in:
a-alpha 2022-11-11 03:27:50 +00:00 committed by Gitee
commit cffffe174d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 23 additions and 8 deletions

View File

@ -68,10 +68,11 @@ func (iio InterIO) RecvUntil(delim_s string) (ret string, rc error) {
output += string(recv)
if ( ( len(recv) >= len(delim_s) ) &&
( bytes.Equal(recv[len(recv) - len(delim_s):], []byte(delim_s)) ) ) {
if ( ( len(recv) >= len(delim_s) ) &&
( bytes.Equal(recv[len(recv) - len(delim_s):],
[]byte(delim_s) ) ) ) {
break
}
} // if ( ( len ...
} // for { ...
ret = output
@ -80,7 +81,9 @@ func (iio InterIO) RecvUntil(delim_s string) (ret string, rc error) {
return ret, rc
}
func (iio InterIO) RecvUntilByte(delim_b byte) (ret string, rc error) {
return ret, rc
func (iio InterIO) RecvUntilByte(delim_b byte) (string, error) {
recv, rc := iio.Reader.ReadBytes(delim_b)
/* */
return string(recv), rc
}

View File

@ -29,7 +29,7 @@
package Sandbox
import (
"fmt"
//"fmt"
"os/exec"
"bufio"
"errors"
@ -58,7 +58,7 @@ func (sbd *SandboxDefault)cmdGuard(binpath string) error {
}
func (sbd *SandboxDefault)Process(binpath string) (inter.InterIO, error) {
// TODO: make ALOG
fmt.Println("Starting process for %s ... \n", binpath)
A_DEBUG_INFO("Starting process for : ", GetSubfixPath(binpath), " ...\n")
// exec.Command will cause security problem, we must make a
// strong guard
@ -88,7 +88,7 @@ func (sbd *SandboxDefault)Process(binpath string) (inter.InterIO, error) {
return inter.InterIO{}, rc
} // if (nil ...
fmt.Println(binpath, ":\n", cmd.Process.Pid, ":\n")
A_DEBUG_INFO("\nbin: ", GetSubfixPath(binpath), "\npid: ", cmd.Process.Pid, "\n")
iio := inter.InterIO {
Reader: bufio.NewReader(stdout),

View File

@ -93,6 +93,12 @@ func GetPrefixPath(path string) string {
return path[:index]
}
func GetSubfixPath(path string) string {
index := strings.LastIndex(path, string(os.PathSeparator))
/* */
return path[(index+1):]
}
func GetSubfixFile(path string) string {
index := strings.LastIndex(path, ".")
/* */

View File

@ -87,6 +87,12 @@ func GetPrefixPath(path string) string {
return path[:index]
}
func GetSubfixPath(path string) string {
index := strings.LastIndex(path, string(os.PathSeparator))
/* */
return path[(index+1):]
}
func GetSubfixFile(path string) string {
index := strings.LastIndex(path, ".")
/* */