Aggressively check for possible buffer overflows in cmd.cgi

Refs #5434