Bug 1669833 - Removed else after the return statement. r=jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D93873
This commit is contained in:
Akshat Dixit 2020-10-17 13:47:13 +00:00
parent c47fc76053
commit f71808cc4b

View file

@ -195,37 +195,40 @@ nsresult nsChromeRegistry::Canonify(nsCOMPtr<nsIURI>& aChromeURL) {
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
return NS_MutateURI(aChromeURL).SetPathQueryRef(path).Finalize(aChromeURL); return NS_MutateURI(aChromeURL).SetPathQueryRef(path).Finalize(aChromeURL);
} else { }
// prevent directory traversals ("..")
// path is already unescaped once, but uris can get unescaped twice // prevent directory traversals ("..")
const char* pos = path.BeginReading(); // path is already unescaped once, but uris can get unescaped twice
const char* end = path.EndReading(); const char* pos = path.BeginReading();
// Must start with [a-zA-Z0-9]. const char* end = path.EndReading();
if (!('a' <= *pos && *pos <= 'z') && !('A' <= *pos && *pos <= 'Z') && // Must start with [a-zA-Z0-9].
!('0' <= *pos && *pos <= '9')) { if (!('a' <= *pos && *pos <= 'z') && !('A' <= *pos && *pos <= 'Z') &&
return NS_ERROR_DOM_BAD_URI; !('0' <= *pos && *pos <= '9')) {
} return NS_ERROR_DOM_BAD_URI;
while (pos < end) { }
switch (*pos) { while (pos < end) {
case ':': switch (*pos) {
case ':':
return NS_ERROR_DOM_BAD_URI;
case '.':
if (pos[1] == '.') {
return NS_ERROR_DOM_BAD_URI; return NS_ERROR_DOM_BAD_URI;
case '.': }
if (pos[1] == '.') return NS_ERROR_DOM_BAD_URI; break;
break; case '%':
case '%': // chrome: URIs with double-escapes are trying to trick us.
// chrome: URIs with double-escapes are trying to trick us. // watch for %2e, and %25 in case someone triple unescapes
// watch for %2e, and %25 in case someone triple unescapes if (pos[1] == '2' &&
if (pos[1] == '2' && (pos[2] == 'e' || pos[2] == 'E' || pos[2] == '5')) {
(pos[2] == 'e' || pos[2] == 'E' || pos[2] == '5')) return NS_ERROR_DOM_BAD_URI;
return NS_ERROR_DOM_BAD_URI; }
break; break;
case '?': case '?':
case '#': case '#':
pos = end; pos = end;
continue; continue;
}
++pos;
} }
++pos;
} }
return NS_OK; return NS_OK;