The first thing you have to realize is you're not dealing with a friendly, old puppy dog. Man's best friend is a wonderful creature, but it's also an animal. Worse, it's a predatory animal. That means that when a dog attacks, its instinct is that of a predator, and the way to prevent serious injury and even death is to acknowledge and respect that instinct.
Never turn your back on a predator in close quarters. If you turn and run, you become nothing more than prey. Instead, face the animal squarely and bend your knees to lower your center of gravity.
Once you're in position, start yelling at the animal as you face it. An attacking dog is expecting you to turn and run. When you face it and act aggressively toward it, you may scare it off. Unfortunately, a trained or determined animal will not be swayed by this tactic.
Regardless of whether the dog is a trained attack dog at the command of a bad guy, or a suddenly irritated and aggressive family pet, be careful about cornering or trapping it. Always give an animal a way out or a way to retreat. Trapping a dog in a corner and leaving him with no other option but to fight his way out is a sure way to get bitten.
If you find you have trapped a dog in a corner, keep facing the dog and slowly start to back away, giving it an escape route. This tactic will work on most dogs that are not committed to the attack but are instead reacting out of fear.