I was doing some work in an old house I recently moved into, and found that my dishwasher and garbage disposal (and some outlets near them) are on a 30 amp breaker. However, some of the electrical wiring going between the disposal and the wall switch is yellow, which implies 12-gauge, 20 amp-rated wire (right?). How dangerous is this situation? What should be done, if anything?
If the #14 or #12 wire is a branch going to specific loads, then it is "safe" with respect to that load. It won't overload that wiring regardless of the breaker capacity use (or even if the breaker is bypassed entirely). However, this is unsafe in the context of changes in usage. The electrical code focuses on safety and rightly prohibits this. The circuit breaker is required to be sized to protect all wiring in the branch circuit it feeds to (and the receptacles, too). This is because someone could overload the circuit (for example plugging in a 12 amp appliance in one outlet and another 12 amp appliance in another outlet on the same circuit, which should trip a 20 amp breaker and would not trip a 30 amp breaker).
In USA, all 15 amp receptacles are actually rated at 20 amps (just not configured to accept a 20 amp plug). So if you have 20 amp wire (usually #12 if the special cases requiring derating do not come into play), you can use a 20 amp breaker (one more exception in the code is if the branch circuit has a single dedicated outlet, it must be protected at the outlet designated amperage).
Since the normal type of outlets don't have a 30 amp capacity, you can't use a 30 amp breaker on them even if you have 30 amp wiring (usually #10), and meet the electrical code. The receptacles can overheat, too. You may need to split circuits if this branch is pulling too much current.
One important thing to remember is that appliances don't always run at full load and therefore don't always consume full power. So it's quite likely that the described setup will run okay for ages. I've seen many circuits running on undersized wires - they didn't even heat up enough to be notices by touching the insulation with one's hand.
Yet the code is there to ensure safe operation with some safety factor. In your case maximum ampacity is 20 amps, so the wire will run at up to 50% overload sometimes. You may be lucky and get away with it or you may be unlucky and get a fire started.
The only way to ensure safe operation is to use wire with at least the required ampacity. In your case it is to replace the undersized segments of the wire.
How about we just use the right wire with the right beakers. Electrical code is written for a reason. there's no way around it in my opinion. When we follow the code we protect our own interests and the interests of our family and customers.
It's bad, with one exception.
There's a reason you can get away with it. Since you're serving hardwired loads, you don't have a case of someone plugging in a microwave and toaster and George Foreman all at the same time. So the hardwired appliance will naturally limit current to safe levels until it malfunctions. And then you'll have no protection at all, and your house will burn.
The law of the land says you don't get to roll the dice like that, and the breaker must be appropriate for the wire and appliance.
The exception relates to certain motor loads. In that case you are allowed to use the normal wire size for that motor, but upsize the breaker based on a formula. A disposal is a motor load, but I would be surprised to see the exception invoked for one of those. More likely it is starting to fail, and "the last guy" upsized the breaker rather than deal with it.