Check for null pointer before deferencing it in cmd_search.

Fixes #1462