Add some NULL checks.
Fix some broken NULL checking.
Avoid possible NULL derefs in packet parsing.