The best way to deal with this is to provide your own, better/more secure/more up-to-date answer. Hopefully this will be seen by those seeking answers and used in preference to the existing, insecure, answer.
You can also leave a comment on the original answer pointing out it's flaws. I know not all people will read the comments, but it still benefits future readers who do, as they know to treat the answer with caution and it also alerts the OP so that they can improve their answer or at the very least insert a disclaimer from themselves that the answer ideal but can be used as the starting point for a good solution (or words to that effect).
You can also down-vote. This sends an clearer signal that the answer isn't up to scratch. Personally, I'd probably reserve my down-vote for particularly egregious cases, but you will probably have different standards to me.
What you shouldn't do is edit your solution into the existing answer or "fix" the code in the existing answer. The big danger here is that, especially for highly up-voted answers, people will think that your code will appear to be co-opting the existing votes. Your code should be peer reviewed on it's own merits.
Editing the warning into the answer is also probably a bad idea. The OP will get notified of the edit and is highly likely to roll it back. Then you get someone else rolling that back and before you know it you have a rollback war.
So, it all comes back to my first statement. The simplest, cleanest and safest solution is to provide your own answer.