View Single Post
10-25-08, 10:11 AM   #4
Telic
A Defias Bandit
 
Telic's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 3
More Causes & Some Solutions

Many AddOns seem to have caused a problem with the Set Focus and Clear Focus drop down menu actions.
Here is a summary of what I've found while 'adjusting' my AddOns to cope with this issue :


TAINT THROUGH ADDON DROP DOWN INITIALISATION / ADDBUTTON
-----------------------------------------------------------------
As defined by UIDropDownMenu.lua, the default number of menu buttons is 8 and the default number of menu frames is 2.
(i.e. a depth of 2 menus)
As larger menus are initialised, UIDropDownMenu creates buttons and menus as required, and stores the numbers created in
UIDROPDOWNMENU_MAXBUTTONS - the number of menu buttons created.
UIDROPDOWNMENU_MAXLEVELS - the number of menu frames created. i.e. opening one drop down from another

When you log in, Blizzard UI code exectues, and these numbers naturally (and securely) increase.
Blizzard UI code and AddOns initialise many drop downs when you log in, so that by the time you are able to execute scripts at the command line, the number of drop down buttons on WotLK Beta is 24.

If ANY AddOn initialises a drop down box that increases either UIDROPDOWNMENU_MAXBUTTONS or UIDROPDOWNMENU_MAXLEVELS beyond the value it has securely reached via Blizzard code, then taint is introduced and Set focus and Clear focus drop down action buttons are blocked.

If you initialise AddOn drop down boxes in their OnLoad functions, then you can very easily introduce taint, as you may cause an increase in the secure number of buttons BEFORE Blizzard's secure code has reached the 'relatively' high value of 24.

If you initialise AddOn drop down boxes in their safer OnShow function, then you usually won't introduce taint as long as it has less than 25 buttons, and only has a menu depth of 2. More than 24 buttons, or a menu depth of 3 or more will cause taint.

There is a sneaky way to increase UIDROPDOWNMENU_MAXBUTTONS to a maximum of 29 without causing taint by using the following code :

Code:
	if ( UIDROPDOWNMENU_MAXBUTTONS < 29 ) then
		local toggle;
		if ( not WorldMapFrame:IsVisible() ) then
			ToggleFrame(WorldMapFrame);
			toggle = true;
		end
		SetMapZoom(2);
		if ( toggle ) then
			ToggleFrame(WorldMapFrame);
		end
	end
This code causes the Eastern Kingdoms zone list to load in the World Map zone drop down, and although you have triggered it from an AddOn, it increases UIDROPDOWNMENU_MAXBUTTONS to 29 without causing taint. Useful if you have a drop down box of your own that needs to list the Eastern Kingdom zones, or any other drop down with 24 to 29 buttons
i.e. execute the above code before initialising your own drop down, and then the buttons up to 29 are securely pre-made for you. Not quite enough for the Atlas maximum buttons, but nearly.

(Note that the above code couldn't be executed in the 'VARIABLES_LOADED' event on WotLK Beta without causing a Blizzard Feedback AddOn error, so needs to be executed in an OnUpdate after VARIABLES_LOADED.)

I'm not sure there's a secure way to increase the menu depth to 3, or the number of buttons beyond 29.
(Although Blizzard could certainly increase their minimum values and save a lot of trouble without even having to investigate why the taint was happening; At the cost of a small amount of memory obviously)



TAINT BY HOOKING
-------------------
If you hook the 'WorldMapFrame_Update' function when UIDROPDOWNMENU_MAXBUTTONS equals 24 (or less), and then open the World Map and go to Eastern Kingdoms to increase the value to 29, then you will have tainted the drop down boxes, as WorldMapFrame_Update was tainted by your hook when the drop down buttons were created.

This means that many of the world map functions that didn't previously need to be hooked securely, now do, to be on the safe side.



TAINT BY BUTTON INSERTION IN TO UnitPopup MENUS
----------------------------------------------------
If you want to add options to the target frame right click menu by adding button information to the UnitPopup.lua arrays, then you will cause taint.
I haven't found any secure way of adding your own buttons to these menus.



TAINT EVEN WHEN YOU THINK ITS SAFE
---------------------------------------
In certain conditions I have found a bug where you can cause taint even though the number of buttons in your menu is LESS than UIDROPDOWNMENU_MAXBUTTONS.

Menus store the number of buttons used in a value associated with the menu frame e.g. DropDownList1.numButtons
When you call UIDropDownMenu_Initialize, the numButtons value should be zeroed, and then incremented each time you AddButton.
However, testing on the WotLK Beta, I have found that this value is sometimes NOT reset to zero, leading to the your buttons being added to the number of buttons included in the previous menu, and therefore leading to the possibility of exceeding UIDROPDOWNMENU_MAXBUTTONS, and causing taint.
The exact cause has been difficult to pin down, but it seems like its happening occasionally when one drop down list is already open when you try to initialise another, possibly when one of the drop downs is deeper than level 1, or when UIDROPDOWNMENU_OPEN_MENU hasn't been updated correctly.

There does seem to be a safe way to avoid this in your own initialisation script, by explicitly resetting .numButtons to zero in your own code - which does NOT seem to lead to taint.
For example, when opening a level 1 drop down list, you can explicitly reset the value :

DropDownList1.numButtons = 0;



COMBAT_TEXT_X_SCALE TAINT
-------------------------------
There is at least one other cause of Set Focus / Clear Focus taint that occurs occasionally, but I haven't pinned down what really causes it.
It reports a taint log saying that COMBAT_TEXT_X_SCALE is tainted in Blizzard_CombatText.lua, finally resulting in the same Focus action blocked.

In this case the taint seems temporary and short lived, and a second attempt to Set Focus or Clear Focus will succeed.
(So I haven't investigated further atm)
  Reply With Quote