willnorris / microformats

Go library for parsing microformats
https://pkg.go.dev/willnorris.com/go/microformats
MIT License
64 stars 6 forks source link

panic: invalid nil pointer dereference #13

Closed nekr0z closed 4 years ago

nekr0z commented 4 years ago

Trying to Parse this page, for example: https://quickthoughts.jgregorymcverry.com/pages/archive

willnorris commented 4 years ago

Hey, thanks for the report! For my own notes, here's the stack trace:

% go run ./cmd/gomf "https://quickthoughts.jgregorymcverry.com/pages/archive"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8c pc=0x69cf26]

goroutine 1 [running]:
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000675340)
        /home/willnorris/src/microformats/go/microformats.go:395 +0x1346
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000675260)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000674d90)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000674cb0)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000672070)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000671f80)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000671ea0)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000671dc0)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000671ce0)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000671c00)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000671b20)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000671a40)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000671960)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc00065ee70)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc00065ed90)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc00065ecb0)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc00065ebd0)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc00065a700)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc00065a620)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc00065a540)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000118150)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.(*parser).walk(0xc00040be28, 0xc000118000)
        /home/willnorris/src/microformats/go/microformats.go:299 +0x305
willnorris.com/go/microformats.ParseNode(0xc000118000, 0xc000128000, 0x0)
        /home/willnorris/src/microformats/go/microformats.go:147 +0xde
willnorris.com/go/microformats.Parse(0x7f40fc562698, 0xc0004ce6e0, 0xc000128000, 0x7f40fc562698)
        /home/willnorris/src/microformats/go/microformats.go:132 +0x5e
main.main()
        /home/willnorris/src/microformats/go/cmd/gomf/main.go:44 +0x37d
exit status 2

It looks like I'm just missing a nil check for p.curItem here. I'll put together a test case, since I'm kind of curious why this has never been hit before.

willnorris commented 4 years ago

okay... it looks like everywhere else I check p.curItem.backcompat, I do a nil check first. So I just overlooked this one. I'll just fix that.

nekr0z commented 4 years ago

Great! Thank you!