internal: check response status in Response.DecodeProp

This commit is contained in:
Simon Ser 2020-01-14 21:35:24 +01:00
parent 388377dfca
commit a4580254eb
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -11,6 +11,10 @@ import (
type Status string type Status string
func (s Status) Err() error { func (s Status) Err() error {
if s == "" {
return nil
}
parts := strings.SplitN(string(s), " ", 3) parts := strings.SplitN(string(s), " ", 3)
if len(parts) != 3 { if len(parts) != 3 {
return fmt.Errorf("webdav: invalid HTTP status %q: expected 3 fields", s) return fmt.Errorf("webdav: invalid HTTP status %q: expected 3 fields", s)
@ -60,6 +64,9 @@ type Response struct {
} }
func (resp *Response) DecodeProp(name xml.Name, v interface{}) error { func (resp *Response) DecodeProp(name xml.Name, v interface{}) error {
if err := resp.Status.Err(); err != nil {
return err
}
for i := range resp.Propstats { for i := range resp.Propstats {
propstat := &resp.Propstats[i] propstat := &resp.Propstats[i]
for j := range propstat.Prop.Raw { for j := range propstat.Prop.Raw {