Bug 463039 - validate values that get passed to clearWatch. r/sr=jst
authorDoug Turner <dougt@meer.net>
Wed, 12 Nov 2008 08:01:40 -0800
changeset 21624 1fe78d659cbe4f3f411f5c49e2393199d4064a1b
parent 21623 693bb0463223cbf8126d4837831e251b71a65997
child 21625 8a26a5d1a9bda2cf3f1728d02dea5547ed175665
push id3624
push userdougt@mozilla.com
push dateThu, 13 Nov 2008 19:59:44 +0000
treeherdermozilla-central@a1364547a182 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs463039
milestone1.9.1b2pre
Bug 463039 - validate values that get passed to clearWatch. r/sr=jst
dom/public/idl/geolocation/nsIDOMGeoGeolocation.idl
dom/src/geolocation/nsGeolocation.cpp
dom/tests/mochitest/geolocation/Makefile.in
--- a/dom/public/idl/geolocation/nsIDOMGeoGeolocation.idl
+++ b/dom/public/idl/geolocation/nsIDOMGeoGeolocation.idl
@@ -36,23 +36,23 @@
 
 #include "domstubs.idl"
 
 interface nsIDOMGeoPosition;
 interface nsIDOMGeoPositionOptions;
 interface nsIDOMGeoPositionCallback;
 interface nsIDOMGeoPositionErrorCallback;
 
-[scriptable, function, uuid(CE495440-C8B9-42DE-B67C-60E6928C0F40)]
+[scriptable, function, uuid(0EC70F3F-7E15-45E0-84E9-CDE078CB150A)]
 interface nsIDOMGeoGeolocation : nsISupports
 {
   readonly attribute nsIDOMGeoPosition lastPosition;
 
   void getCurrentPosition(in nsIDOMGeoPositionCallback successCallback,
                           [optional] in nsIDOMGeoPositionErrorCallback errorCallback,
                           [optional] in nsIDOMGeoPositionOptions options);
 
-  unsigned short watchPosition(in nsIDOMGeoPositionCallback successCallback,
-                               [optional] in nsIDOMGeoPositionErrorCallback errorCallback,
-                               [optional] in nsIDOMGeoPositionOptions options);
+  long watchPosition(in nsIDOMGeoPositionCallback successCallback,
+                     [optional] in nsIDOMGeoPositionErrorCallback errorCallback,
+                     [optional] in nsIDOMGeoPositionOptions options);
 
-  void clearWatch(in unsigned short watchId);
+  void clearWatch(in long watchId);
 };
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -748,17 +748,17 @@ nsGeolocation::GetCurrentPosition(nsIDOM
   mPendingCallbacks.AppendElement(request);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGeolocation::WatchPosition(nsIDOMGeoPositionCallback *aCallback,
                              nsIDOMGeoPositionErrorCallback *aErrorCallback,
                              nsIDOMGeoPositionOptions *aOptions, 
-                             PRUint16 *_retval NS_OUTPARAM)
+                             PRInt32 *_retval NS_OUTPARAM)
 {
   nsCOMPtr<nsIGeolocationPrompt> prompt = do_GetService(NS_GEOLOCATION_PROMPT_CONTRACTID);
   if (prompt == nsnull)
     return NS_ERROR_NOT_AVAILABLE;
 
   if (mWatchingCallbacks.Length() > MAX_GEO_REQUESTS_PER_WINDOW)
     return NS_ERROR_NOT_AVAILABLE;
 
@@ -773,18 +773,23 @@ nsGeolocation::WatchPosition(nsIDOMGeoPo
 
   // need to hand back an index/reference.
   mWatchingCallbacks.AppendElement(request);
   *_retval = mWatchingCallbacks.Length() - 1;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsGeolocation::ClearWatch(PRUint16 aWatchId)
+nsGeolocation::ClearWatch(PRInt32 aWatchId)
 {
+  PRUint32 count = mWatchingCallbacks.Length();
+
+  if (aWatchId < 0 || count == 0 || aWatchId > count + 1)
+    return NS_ERROR_FAILURE;
+
   mWatchingCallbacks[aWatchId]->MarkCleared();
   return NS_OK;
 }
 
 PRBool
 nsGeolocation::OwnerStillExists()
 {
   if (!mOwner)
--- a/dom/tests/mochitest/geolocation/Makefile.in
+++ b/dom/tests/mochitest/geolocation/Makefile.in
@@ -47,16 +47,17 @@ include $(topsrcdir)/config/rules.mk
 _TEST_FILES	= \
 		test_lastPosition.html \
 		test_manyWindows.html \
 		test_allowCurrent.html \
 		test_allowWatch.html \
 		test_cancelCurrent.html \
 		test_cancelWatch.html \
 		test_clearWatch.html \
+		test_clearWatch_invalid.html \
 		test_geoPrompt.html \
 		test_timeoutWatch.html \
 		prompt_common.js       \
 		geolocation_common.js  \
 		geolocation.html \
 		test_optional_api_params.html \
 		$(NULL)