bugsnag / bugsnag-go

Automatic panic monitoring for Go and Go web frameworks, like negroni, gin, and revel
https://docs.bugsnag.com/platforms/go
MIT License
204 stars 69 forks source link

sanitizer.Sanitize may cause panic #222

Closed wzy9607 closed 7 months ago

wzy9607 commented 7 months ago

Describe the bug

sanitizer.Sanitize may cause panic by calling value method using nil pointer.

Steps to reproduce

  1. Run the Example code snippet
  2. See a panic

Environment

Example code snippet

package main

import (
    "errors"

    bugsnago "github.com/bugsnag/bugsnag-go/v2"
)

type Name struct {
    name string
}

func (n Name) String() string {
    return n.name
}

type data struct {
    Name *Name
}

func main() {
    err := errors.New("error")
    meta := bugsnago.MetaData{}
    meta.AddStruct("data", map[string]any{
        "data": data{Name: nil},
    })
    _ = bugsnago.Notify(err, meta)
}
Error messages: ``` panic: value method main.Name.String called using nil *Name pointer goroutine 1 [running]: main.(*Name).String(0xc00006c0e0?) :1 +0x25 github.com/bugsnag/bugsnag-go/v2.sanitizer.Sanitize({{0x0, 0x0, 0x0}, {0xc00002e240, 0x3, 0x4}}, {0xec50fc0, 0x0}) /Users/user/go/pkg/mod/github.com/bugsnag/bugsnag-go/v2@v2.3.0/metadata.go:98 +0x7b ... ... ... ```
wzy9607 commented 7 months ago

I see there is already a pr #221 fixing this, so I'll close this issue.

DariaKunoichi commented 7 months ago

@wzy9607 Hey, the fix is merged and released in v2.3.1.