fix(upnp): guard against out of index string access (#10834)
Broken responses may have empty path component. Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
+1
-1
@@ -554,7 +554,7 @@ func replaceRawPath(u *url.URL, rp string) {
|
|||||||
q = fs[1]
|
q = fs[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
if p[0] == '/' {
|
if p != "" && p[0] == '/' {
|
||||||
u.Path = p
|
u.Path = p
|
||||||
} else {
|
} else {
|
||||||
u.Path += p
|
u.Path += p
|
||||||
|
|||||||
@@ -79,3 +79,16 @@ func TestControlURLParsing(t *testing.T) {
|
|||||||
t.Error("URL normalization of", subject, "failed; expected", expected, "got", u.String())
|
t.Error("URL normalization of", subject, "failed; expected", expected, "got", u.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestControlURLParsingQueryOnly(t *testing.T) {
|
||||||
|
rootURL := "http://192.168.243.1:80/igd.xml"
|
||||||
|
|
||||||
|
u, _ := url.Parse(rootURL)
|
||||||
|
subject := "?control=WANCommonIFC1"
|
||||||
|
expected := "http://192.168.243.1:80/igd.xml?control=WANCommonIFC1"
|
||||||
|
replaceRawPath(u, subject)
|
||||||
|
|
||||||
|
if u.String() != expected {
|
||||||
|
t.Error("URL normalization of", subject, "failed; expected", expected, "got", u.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user