In your particular example, there are a number of international organizations in that area, like the Arab League, the CCASG and the OPEC, which have the UAE as a member. Even if Iran would suddenly start to become as aggresive as North Korea and threaten to shoot down aircraft entering their region, the political and economical repercussions of actually doing so would be extremely severe. They would face embargos, cancellations of trade treaties, heavy sanctions and worldwide punishments. It might even be seen as an act of war, which might start an actual war involving the Arab League.
The threat of an attack from afghanistan is not as likely. Most of the Afghan terrorist weaponry dates back to the Russian invasion of Afghanistan and involves shoulder weaponry with shorter range and outdated launcher platforms. The missiles themselves often don't have an operational range long enough to attack an aircraft flying at 40,000 feet at 900 km/h.
Pakistan's government has been stable for a while and even though diplomatic relations have deteriorated somewhat after the death of Bin Laden, the pakistani government would not take kindly to terrorists taking down a plane from their soil, let alone that they would take one down themselves.
In all cases, any attack originating from the ground of one of those states would have severe international repercussions and can easily lead to political, economical and possibly military action towards that state. Even if it's an action from a splinter group located in that country, it could still lead to military intervention, like happened in Afghanistan after the attacks of 9/11 by Al Qaeda. There are not many splinter groups who would commit such an act of terror with such a prospect.