Because of the unfortunate amount of cancer patients, there is a significant amount of data on many aspects of cancer as it pertains to organ donation. In simple terms, this means doctors know when organs can be safely donated or not. For example, a brain tumor that has yet to spread further than the brain stem can, in fact, make the deceased's organs still eligible for donation. Contrastingly, former cancer patients can donate particular organs depending on the extent of their cancer and how long they have been cancer-free.
The practice of organ donation is designed with the health of patients in mind. Even if there is a small risk involved, this is true regardless of the cancer status of the donor. Furthermore, there are situations where an individual needs a donation quickly. However, they still do not allow organs of poor quality to be donated. This means that organ donors aren't accepted if they are a medical risk merely because some organs are better than none. Organs have to meet a quality threshold no matter what.
There is a notable case of organ recipients receiving cancer, but the patient was misdiagnosed and doctors were unaware that the cancer even existed. Had they been aware, the organs would not have been viable for donation. Of course, this is an extremely rare situation, and it's not worth worrying about. Except, of course, if you're in charge of ensuring the safety of organs for donation. But if you're a patient receiving an organ or a potential donor, you have no need to worry. Furthermore, you are entrusting them with the responsibility of using proper procedures to ensure lives are saved, not lost. If something does happen, it will either be a rare and unforeseeable accident or the fault of someone in the medical field.
One reason there is a shortage of organ donors is that those with certain illnesses or of a certain age are under the impression that they can't donate. This is usually not the case as many people from all sorts of backgrounds can qualify for becoming an organ donor. There are systems in place to ensure quality organs are provided to patients. While it would be both morally and legally inappropriate, someone who lied about their medical history would not succeed in donating a dangerous organ. There are tests and procedures in place to ensure that everything is running smoothly.