Correlation between threat and odour, taste
The compounds that smell bad to us are often the same ones produced by the anaerobic metabolism of bacteria, such as hydrogen sulfides or butyric acid. These types of compounds are the ones that make excrement and rotting food smell bad, and if something is giving is giving off a lot of them it's a pretty good signal to not put it in your mouth. Vomit also has quite a lot of butyric acid in it, so we may be particularly sensitive to it.

Plants produce toxic compounds to stop herbivory, many of them taste bitter. Alkaloids are often toxic and uniformly bitter, terpenoids are another example.

There's nothing obviously different from a chemical perspective in chemicals that smell bad. Butyric acid is just a 4 carbon chain with a couple of oxygens on the end and reeks, while the compound propanediol (which is 4 carbons with an oxygen on each end) is used in deodorants. If a compound has a strong smell or taste to us, it is because that compound has been important to us during our evolution. That doesn't mean it's a perfect indicator; cheeses can stink and be totally edible, but that's because the compounds in that cheese usually are a sign of something dangerous.