Skip to content

Commit 05b3de1

Browse files
committed
xhyve: Fix included '\tappend\s' in kexec boot option
Remove '\tappend\s' using regexp.FindStringSubmatch - ref: https://regex101.com/r/LghmGX/5 Ignore os.Open error is not good on readLine even if strings.Contains Use return instead of break and remove alocate 'line' variable Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
1 parent 261fa05 commit 05b3de1

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

xhyve/xhyve.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package xhyve
22

33
import (
44
"archive/tar"
5-
"bytes"
65
"bufio"
6+
"bytes"
77
"errors"
88
"fmt"
99
"io"
@@ -85,7 +85,7 @@ var (
8585
ErrMachineNotExist = errors.New("machine does not exist")
8686
diskRegexp = regexp.MustCompile("^/dev/disk([0-9]+)")
8787
kernelRegexp = regexp.MustCompile(`(vmlinu[xz]|bzImage)[\d]*`)
88-
kernelOptionRegexp = regexp.MustCompile(`(\t|\s{2})append`)
88+
kernelOptionRegexp = regexp.MustCompile(`(?:\t|\s{2})append\s+([[:print:]]+)`)
8989
)
9090

9191
// NewDriver creates a new VirtualBox driver with default settings.
@@ -612,43 +612,45 @@ func (d *Driver) publicSSHKeyPath() string {
612612
return d.GetSSHKeyPath() + ".pub"
613613
}
614614

615-
func readLine(path string) string {
616-
line := ""
615+
func readLine(path string) (string, error) {
617616
inFile, err := os.Open(path)
618617
if err != nil {
619-
log.Debugf("Not able to open %s", path)
618+
return "", err
620619
}
621620
defer inFile.Close()
621+
622622
scanner := bufio.NewScanner(inFile)
623-
scanner.Split(bufio.ScanLines)
624623
for scanner.Scan() {
625-
line = scanner.Text()
626-
if kernelOptionRegexp.MatchString(line) {
627-
break
624+
if kernelOptionRegexp.Match(scanner.Bytes()) {
625+
m := kernelOptionRegexp.FindSubmatch(scanner.Bytes())
626+
return string(m[1]), nil
628627
}
629628
}
630-
return line
629+
return "", fmt.Errorf("couldn't find kernel option from %s image", path)
631630
}
632631

633632
func (d *Driver) extractKernelOptions() error {
634-
log.Debugf("Extracting Kernel Options...")
635633
volumeRootDir := d.ResolveStorePath(isoMountPath)
636634
if d.BootCmd == "" {
637635
err := filepath.Walk(volumeRootDir, func(path string, f os.FileInfo, err error) error {
638636
if strings.Contains(path, "isolinux.cfg") {
639-
d.BootCmd = readLine(path)
637+
d.BootCmd, err = readLine(path)
638+
if err != nil {
639+
return err
640+
}
640641
}
641642
return nil
642643
})
643644
if err != nil {
644645
return err
645646
}
647+
646648
if d.BootCmd == "" {
647-
err = errors.New("Not able to parse isolinux.cfg, Please use --xhyve-boot-cmd option")
648-
return err
649+
return errors.New("Not able to parse isolinux.cfg, Please use --xhyve-boot-cmd option")
649650
}
650651
}
651-
log.Debugf("Extracted Options %s", d.BootCmd)
652+
653+
log.Debugf("Extracted Options %q", d.BootCmd)
652654
return nil
653655
}
654656

@@ -661,6 +663,7 @@ func (d *Driver) extractKernelImages() error {
661663
return err
662664
}
663665

666+
log.Debugf("Extracting Kernel Options...")
664667
if err := d.extractKernelOptions(); err != nil {
665668
return err
666669
}

0 commit comments

Comments
 (0)