Check for NULL strings before getting their lengths

Problem reported by Karsten Trulsen

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
4 jobs for master in 8 minutes and 44 seconds (queued for 1 second)