andybalholm / cascadia

CSS selector library in Go
BSD 2-Clause "Simplified" License
697 stars 65 forks source link

Null pointer dereference #56

Closed pkitszel closed 2 years ago

pkitszel commented 2 years ago

Hi,

my project is using this one as a lib. After some slight changes on webpage that it parsers there is a panic: https://github.com/Komosa/cf/issues/4

I suppose there is just a need to handle it around lines from stacktrace. But filling an issue for reference. offending line: gopath.../github.com/andybalholm/cascadia/selector.go:217

andybalholm commented 2 years ago

Are you passing in a nil Node?

midir99 commented 2 years ago

Hey @pkitszel !

I was running into a similar problem few days ago:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x649b8d]

goroutine 63 [running]:
github.com/andybalholm/cascadia.queryInto(0x6bd756?, {0x7f7a1ec38f30, 0xc00129efb0}, {0x0?, 0x64f920?, 0x735300?})
        /home/yoryo/go/pkg/mod/github.com/andybalholm/cascadia@v1.3.1/selector.go:139 +0x2d
github.com/andybalholm/cascadia.QueryAll(...)
        /home/yoryo/go/pkg/mod/github.com/andybalholm/cascadia@v1.3.1/selector.go:152
github.com/midir99/radar/ws.QueryAll(0xc00001efc0?, {0x6bd756?, 0xc000048d38?})
        /home/yoryo/projects/desaparecidos/radar/ws/ws.go:39 +0x71
github.com/midir99/radar/ws.ScrapeGroAlbaAlerts(0x0?, 0x0?)
        /home/yoryo/projects/desaparecidos/radar/ws/gro.go:61 +0x96
created by main.main
        /home/yoryo/projects/desaparecidos/radar/main.go:14 +0x73
exit status 2

But it was all my fault as I was passing a nil pointer to QueryAll in the n *html.Node parameter, all I had to do was adding a validation, so maybe that is what is causing your problem.

pkitszel commented 2 years ago

I've just waited a few days, webpage was likely fixed.

pt., 22 lip 2022, 02:08 użytkownik midir99 @.***> napisał:

Hey @pkitszel https://github.com/pkitszel !

I was running into a similar problem few days ago:

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x649b8d]

goroutine 63 [running]:github.com/andybalholm/cascadia.queryInto(0x6bd756?, {0x7f7a1ec38f30, 0xc00129efb0}, {0x0?, 0x64f920?, 0x735300?}) @./selector.go:139 +0x2dgithub.com/andybalholm/cascadia.QueryAll(...) @./selector.go:152github.com/midir99/radar/ws.QueryAll(0xc00001efc0?, {0x6bd756?, 0xc000048d38?}) /home/yoryo/projects/desaparecidos/radar/ws/ws.go:39 +0x71github.com/midir99/radar/ws.ScrapeGroAlbaAlerts(0x0?, 0x0?) /home/yoryo/projects/desaparecidos/radar/ws/gro.go:61 +0x96 created by main.main /home/yoryo/projects/desaparecidos/radar/main.go:14 +0x73 exit status 2

But it was all my fault as I was passing a nil pointer to QueryAll https://pkg.go.dev/github.com/andybalholm/cascadia#QueryAll in the n *html.Node parameter, all I had to do was adding a validation, so maybe that is what is causing your problem.

— Reply to this email directly, view it on GitHub https://github.com/andybalholm/cascadia/issues/56#issuecomment-1192045772, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM3Q6QXWR3NREBU5GK6RPG3VVHQ6DANCNFSM5XUHGUGQ . You are receiving this because you were mentioned.Message ID: @.***>