aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-04-12 04:00:03 +0700
committerShulhan <ms@kilabit.info>2021-04-12 12:00:01 +0700
commit9cdfa9cd293105ad41345d5dd2af71e7dd10d656 (patch)
tree61021b78074d2662a048e3db292776235f8d6947
parentebbc6775c9c5698b18d1f2e08450641945ce26ff (diff)
downloadawwan-9cdfa9cd293105ad41345d5dd2af71e7dd10d656.tar.xz
all: check and return an error if start index is out of range
-rw-r--r--command.go3
-rw-r--r--script.go2
2 files changed, 5 insertions, 0 deletions
diff --git a/command.go b/command.go
index 0496e5f..aa18c28 100644
--- a/command.go
+++ b/command.go
@@ -83,6 +83,9 @@ func NewCommand(mode, scriptPath string, startAt, endAt int) (cmd *Command, err
return nil, fmt.Errorf("%s: %w", logp, err)
}
+ if cmd.scriptStart >= len(cmd.script.Statements) {
+ return nil, fmt.Errorf("%s: start index out of range", logp)
+ }
if cmd.scriptEnd >= len(cmd.script.Statements) {
cmd.scriptEnd = len(cmd.script.Statements) - 1
}
diff --git a/script.go b/script.go
index 10c09a9..df669bd 100644
--- a/script.go
+++ b/script.go
@@ -68,6 +68,8 @@ func parseScript(env *environment, content []byte) (s *script, err error) {
}
stmts := bytes.Split(buf.Bytes(), []byte{'\n'})
+ // Add empty line at the beginning to make the start index start from
+ // 1, not 0.
stmts = append([][]byte{{}}, stmts...)
s = &script{