Explain the mechanics of binary exploitation, specifically how a buffer overflow occurs and how modern operating systems mitigate this risk.