From f3e520841e22af1e393244f6f2c7dab27e73c44a Mon Sep 17 00:00:00 2001 From: "locka%iol.ie" Date: Mon, 26 May 2003 12:14:17 +0000 Subject: [PATCH] Check for invalid combination of load flags. b=87353 r=radha@netscape.com sr=blizzard@mozilla.org --- docshell/base/nsDocShell.cpp | 2 ++ docshell/base/nsDocShell.h | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index ee9ac19a110..5da2b1092c0 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -4917,6 +4917,8 @@ nsDocShell::InternalLoad(nsIURI * aURI, return NS_ERROR_NULL_POINTER; } + NS_ENSURE_TRUE(IsValidLoadType(aLoadType), NS_ERROR_INVALID_ARG); + // wyciwyg urls can only be loaded through history. Any normal load of // wyciwyg through docshell is illegal. Disallow such loads. if (aLoadType & LOAD_CMD_NORMAL) { diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 58487d4aa2b..ad2176db5b1 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -86,7 +86,12 @@ /* load commands were moved to nsIDocShell.h */ -/* load types are legal combinations of load commands and flags */ +/* load types are legal combinations of load commands and flags + * + * NOTE: + * Remember to update the IsValidLoadType function below if you change this + * enum to ensure bad flag combinations will be rejected. + */ enum LoadType { LOAD_NORMAL = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_NONE), LOAD_NORMAL_REPLACE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY), @@ -99,7 +104,27 @@ enum LoadType { LOAD_REFRESH = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_REFRESH), LOAD_RELOAD_CHARSET_CHANGE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE), LOAD_BYPASS_HISTORY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY) + // NOTE: Adding a new value? Remember to update IsValidLoadType! }; +static inline PRBool IsValidLoadType(PRUint32 aLoadType) +{ + switch (aLoadType) + { + case LOAD_NORMAL: + case LOAD_NORMAL_REPLACE: + case LOAD_HISTORY: + case LOAD_RELOAD_NORMAL: + case LOAD_RELOAD_BYPASS_CACHE: + case LOAD_RELOAD_BYPASS_PROXY: + case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE: + case LOAD_LINK: + case LOAD_REFRESH: + case LOAD_RELOAD_CHARSET_CHANGE: + case LOAD_BYPASS_HISTORY: + return PR_TRUE; + } + return PR_FALSE; +} /* internally used ViewMode types */ enum ViewMode {