fix potential nil deref

This commit is contained in:
Christopher Poile 2023-08-04 16:44:35 +09:00
parent f3e1f7b276
commit 095bcd496e
No known key found for this signature in database
GPG Key ID: 9A44D32A3E15A411
2 changed files with 5 additions and 1 deletions

View File

@ -54,6 +54,7 @@ func (a *App) parseOpenGraphMetadata(requestURL string, body io.Reader, contentT
if err := og.ProcessHTML(body); err != nil {
mlog.Warn("parseOpenGraphMetadata processing failed", mlog.String("requestURL", requestURL), mlog.Err(err))
return nil, nil, errors.New("parseOpenGraphMetadata processing failed")
}
makeOpenGraphURLsAbsolute(og, requestURL)

View File

@ -800,7 +800,10 @@ func (a *App) parseLinkMetadata(requestURL string, body io.Reader, contentType s
image, err := parseImages(io.LimitReader(body, MaxMetadataImageSize))
return nil, image, err
} else if strings.HasPrefix(contentType, "text/html") {
og, _, _ := a.parseOpenGraphMetadata(requestURL, body, contentType)
og, _, err := a.parseOpenGraphMetadata(requestURL, body, contentType)
if err != nil {
return nil, nil, nil
}
// The OpenGraph library and Go HTML library don't error for malformed input, so check that at least
// one of these required fields exists before returning the OpenGraph data