Bad software is a symptom, not the cause.
SW has an input problem and a testability problem. On one hand, the inputs to the SW are not limited (iMessage happily accepts any image file) and testing is limited to some known inputs. Software vulnerability assesment (worst case analysis) is usually performed outside of the development process at very high costs and limited outcome.
It's probably true of lots of aspects of product design - if it's not driven from the top, it's mediocre.