Bug 726502 - nsDeviceMotion::DeviceMotionChanged may index out of bounds mWindowListeners array. r=smaug

This commit is contained in:
Doug Turner 2012-03-09 08:41:25 -08:00
Родитель 73e5d03a75
Коммит 9f0bc0257b
1 изменённых файлов: 17 добавлений и 8 удалений

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

@ -199,12 +199,15 @@ NS_IMETHODIMP nsDeviceMotion::RemoveListener(nsIDeviceMotionListener *aListener)
NS_IMETHODIMP nsDeviceMotion::AddWindowListener(nsIDOMWindow *aWindow)
{
if (mWindowListeners.IndexOf(aWindow) != NoIndex)
return NS_OK;
if (mStarted == false) {
mStarted = true;
Startup();
}
if (mWindowListeners.IndexOf(aWindow) == NoIndex)
mWindowListeners.AppendElement(aWindow);
mWindowListeners.AppendElement(aWindow);
return NS_OK;
}
@ -224,28 +227,34 @@ nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z)
if (!mEnabled)
return NS_ERROR_NOT_INITIALIZED;
for (PRUint32 i = mListeners.Count(); i > 0 ; ) {
nsCOMArray<nsIDeviceMotionListener> listeners = mListeners;
for (PRUint32 i = listeners.Count(); i > 0 ; ) {
--i;
nsRefPtr<nsDeviceMotionData> a = new nsDeviceMotionData(type, x, y, z);
mListeners[i]->OnMotionChange(a);
listeners[i]->OnMotionChange(a);
}
for (PRUint32 i = mWindowListeners.Length(); i > 0 ; ) {
nsCOMArray<nsIDOMWindow> windowListeners;
for (PRUint32 i = windowListeners.Count(); i > 0 ; ) {
windowListeners.AppendObject(mWindowListeners[i]);
}
for (PRUint32 i = windowListeners.Count(); i > 0 ; ) {
--i;
// check to see if this window is in the background. if
// it is, don't send any device motion to it.
nsCOMPtr<nsPIDOMWindow> pwindow = do_QueryInterface(mWindowListeners[i]);
nsCOMPtr<nsPIDOMWindow> pwindow = do_QueryInterface(windowListeners[i]);
if (!pwindow ||
!pwindow->GetOuterWindow() ||
pwindow->GetOuterWindow()->IsBackground())
continue;
nsCOMPtr<nsIDOMDocument> domdoc;
mWindowListeners[i]->GetDocument(getter_AddRefs(domdoc));
windowListeners[i]->GetDocument(getter_AddRefs(domdoc));
if (domdoc) {
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mWindowListeners[i]);
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(windowListeners[i]);
if (type == nsIDeviceMotionData::TYPE_ACCELERATION)
FireDOMMotionEvent(domdoc, target, x, y, z);
else if (type == nsIDeviceMotionData::TYPE_ORIENTATION)