Corporate giving is not usually done quietly - a media campaign highlighting their generosity is the least that most companies expect to get out of a donation. There is no avoiding the fact that if a charity accepts money from a company, their brands will be linked, and a charity will be widely assumed to be endorsing its donor's behaviour.
There is nothing wrong with this, but charities need to be clear and consistent about what they consider to be acceptable company behaviour.
Most will not take money from those whose practices they think contradict their aims. Some take this a step further, though, and if they think their reputation may be jeopardised through association with a company, they will avoid it.
Whatever a charity's approach to ethics, some kind of policy should exist and permeate the whole organisation. There is no point in the fundraising department making a statement by turning down a donation if the charity already has investments in the same company.
Ethics are not clear cut - most corporate money will be tainted somewhere along the line, and what is completely unethical behaviour to one person may be acceptable to another. Charity staff are not investigative journalists, and don't have the time or resources to dedicate to in-depth research, so cracks are bound to appear. But by having a policy, charities have a strong defence and can show they have done all they can to make sure standards are upheld.
Most will not get involved with organisations whose activities directly contradict the goals of the charity - for example environmental organisations would be unlikely to take money from oil companies.
In the end, deciding whom to take money from, or where to make investments, is a minefield - no matter what you decide, there could be a problem.