More often than not, the target in a mergers and acquisitions deal is a financially strapped enterprise that is fast running out of time.

At first glance, it seems simple — and cheap — to snap up a dying company. But tech lawyers are finding that buying bankrupt, or nearly bankrupt, companies requires an artful approach and packs a wide range of risks.