Add a few missing null-checks. Return error code from GetRuleLine() when it fails. b=462787 r+sr=dbaron

This commit is contained in:
Mats Palmgren 2008-12-16 12:26:42 +01:00
Родитель 4dd0535874
Коммит 5ea7d22a43
4 изменённых файлов: 152 добавлений и 12 удалений

Просмотреть файл

@ -71,6 +71,9 @@ endif
ifndef MOZ_NO_INSPECTOR_APIS ifndef MOZ_NO_INSPECTOR_APIS
PARALLEL_DIRS += inspector/public inspector/src PARALLEL_DIRS += inspector/public inspector/src
ifdef ENABLE_TESTS
PARALLEL_DIRS += inspector/tests
endif
endif endif
DIRS += build DIRS += build

Просмотреть файл

@ -73,9 +73,10 @@ NS_IMETHODIMP
inDOMUtils::IsIgnorableWhitespace(nsIDOMCharacterData *aDataNode, inDOMUtils::IsIgnorableWhitespace(nsIDOMCharacterData *aDataNode,
PRBool *aReturn) PRBool *aReturn)
{ {
NS_PRECONDITION(aDataNode, "Must have a character data node");
NS_PRECONDITION(aReturn, "Must have an out parameter"); NS_PRECONDITION(aReturn, "Must have an out parameter");
NS_ENSURE_ARG_POINTER(aDataNode);
*aReturn = PR_FALSE; *aReturn = PR_FALSE;
nsCOMPtr<nsIContent> content = do_QueryInterface(aDataNode); nsCOMPtr<nsIContent> content = do_QueryInterface(aDataNode);
@ -119,6 +120,8 @@ inDOMUtils::GetParentForNode(nsIDOMNode* aNode,
PRBool aShowingAnonymousContent, PRBool aShowingAnonymousContent,
nsIDOMNode** aParent) nsIDOMNode** aParent)
{ {
NS_ENSURE_ARG_POINTER(aNode);
// First do the special cases -- document nodes and anonymous content // First do the special cases -- document nodes and anonymous content
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(aNode)); nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(aNode));
nsCOMPtr<nsIDOMNode> parent; nsCOMPtr<nsIDOMNode> parent;
@ -151,7 +154,7 @@ NS_IMETHODIMP
inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement, inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement,
nsISupportsArray **_retval) nsISupportsArray **_retval)
{ {
if (!aElement) return NS_ERROR_NULL_POINTER; NS_ENSURE_ARG_POINTER(aElement);
*_retval = nsnull; *_retval = nsnull;
@ -194,12 +197,14 @@ NS_IMETHODIMP
inDOMUtils::GetRuleLine(nsIDOMCSSStyleRule *aRule, PRUint32 *_retval) inDOMUtils::GetRuleLine(nsIDOMCSSStyleRule *aRule, PRUint32 *_retval)
{ {
*_retval = 0; *_retval = 0;
if (!aRule)
return NS_OK; NS_ENSURE_ARG_POINTER(aRule);
nsCOMPtr<nsICSSStyleRuleDOMWrapper> rule = do_QueryInterface(aRule); nsCOMPtr<nsICSSStyleRuleDOMWrapper> rule = do_QueryInterface(aRule);
nsCOMPtr<nsICSSStyleRule> cssrule; nsCOMPtr<nsICSSStyleRule> cssrule;
rule->GetCSSStyleRule(getter_AddRefs(cssrule)); nsresult rv = rule->GetCSSStyleRule(getter_AddRefs(cssrule));
if (cssrule) NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(cssrule != nsnull, NS_ERROR_FAILURE);
*_retval = cssrule->GetLineNumber(); *_retval = cssrule->GetLineNumber();
return NS_OK; return NS_OK;
} }
@ -207,14 +212,14 @@ inDOMUtils::GetRuleLine(nsIDOMCSSStyleRule *aRule, PRUint32 *_retval)
NS_IMETHODIMP NS_IMETHODIMP
inDOMUtils::GetBindingURLs(nsIDOMElement *aElement, nsIArray **_retval) inDOMUtils::GetBindingURLs(nsIDOMElement *aElement, nsIArray **_retval)
{ {
NS_ENSURE_ARG_POINTER(aElement);
return mCSSUtils->GetBindingURLs(aElement, _retval); return mCSSUtils->GetBindingURLs(aElement, _retval);
} }
NS_IMETHODIMP NS_IMETHODIMP
inDOMUtils::SetContentState(nsIDOMElement *aElement, PRInt32 aState) inDOMUtils::SetContentState(nsIDOMElement *aElement, PRInt32 aState)
{ {
if (!aElement) NS_ENSURE_ARG_POINTER(aElement);
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIEventStateManager> esm = inLayoutUtils::GetEventStateManagerFor(aElement); nsCOMPtr<nsIEventStateManager> esm = inLayoutUtils::GetEventStateManagerFor(aElement);
if (esm) { if (esm) {
@ -232,8 +237,7 @@ inDOMUtils::GetContentState(nsIDOMElement *aElement, PRInt32* aState)
{ {
*aState = 0; *aState = 0;
if (!aElement) NS_ENSURE_ARG_POINTER(aElement);
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIEventStateManager> esm = inLayoutUtils::GetEventStateManagerFor(aElement); nsCOMPtr<nsIEventStateManager> esm = inLayoutUtils::GetEventStateManagerFor(aElement);
if (esm) { if (esm) {

Просмотреть файл

@ -0,0 +1,52 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = layout/inspector/tests
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES =\
test_bug462787.html \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)

Просмотреть файл

@ -0,0 +1,81 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=462787
-->
<head>
<title>Test for Bug 462787</title>
<script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=462787">Mozilla Bug 462787</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 462787 **/
function do_test() {
const INVALID_POINTER = 0x80004003;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = Components.classes["@mozilla.org/inspector/dom-utils;1"]
.getService(Components.interfaces.inIDOMUtils);
try {
utils.getCSSStyleRules(null);
ok(false, "expected an exception");
}
catch(e) { is(e.result, INVALID_POINTER, "got the expected exception"); }
try {
utils.getRuleLine(null);
ok(false, "expected an exception");
}
catch(e) { is(e.result, INVALID_POINTER, "got the expected exception"); }
try {
utils.isIgnorableWhitespace(null);
ok(false, "expected an exception");
}
catch(e) { is(e.result, INVALID_POINTER, "got the expected exception"); }
try {
utils.getParentForNode(null, true);
ok(false, "expected an exception");
}
catch(e) { is(e.result, INVALID_POINTER, "got the expected exception"); }
try {
utils.getBindingURLs(null);
ok(false, "expected an exception");
}
catch(e) { is(e.result, INVALID_POINTER, "got the expected exception"); }
try {
utils.getContentState(null);
ok(false, "expected an exception");
}
catch(e) { is(e.result, INVALID_POINTER, "got the expected exception"); }
try {
utils.setContentState(null, false);
ok(false, "expected an exception");
}
catch(e) { is(e.result, INVALID_POINTER, "got the expected exception"); }
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(do_test);
</script>
</pre>
</body>
</html>