Software vulnerabilities can happen due to two primary reasons:
Flaws in the program design, such as a loophole in the logic function.
Error in the program source code.