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

nil pointer deref for xpath //, //* works #38

Closed
tv42 opened this issue Nov 1, 2019 · 0 comments
Closed

nil pointer deref for xpath //, //* works #38

tv42 opened this issue Nov 1, 2019 · 0 comments

Comments

@tv42
Copy link

tv42 commented Nov 1, 2019

Either xpath.MustCompile needs to fail, or xpath.Expr.Select needs to not crash.

$ head -999 go.mod main.go
==> go.mod <==
module example.com/m

go 1.13

require (
	github.com/antchfx/htmlquery v1.1.0
	github.com/antchfx/xpath v1.1.0
	golang.org/x/net v0.0.0-20191101175033-0deb6923b6d9
)

==> main.go <==
package main

import (
	"log"
	"strings"

	"github.com/antchfx/htmlquery"
	"github.com/antchfx/xpath"
	"golang.org/x/net/html"
)

func main() {
	const doc = ``
	tree, err := html.Parse(strings.NewReader(doc))
	if err != nil {
		log.Fatalf("html parse: %v", err)
	}
	exp := xpath.MustCompile(`//`)
	_ = htmlquery.QuerySelector(tree, exp)
}
$ go run .
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x6950c1]

goroutine 1 [running]:
github.com/antchfx/xpath.(*Expr).Select(...)
	github.com/antchfx/xpath@v1.1.0/xpath.go:130
github.com/antchfx/htmlquery.QuerySelector(0xc0000ca230, 0x0, 0x0)
	github.com/antchfx/htmlquery@v1.1.0/query.go:70 +0x61
main.main()
	example.com/m@/main.go:19 +0x10a
exit status 2
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants