Aggressively check for possible buffer overflows in cmd.cgi

Refs #5434
Merge branch 'fix/cmd-5434' into support/1.10

Refs #5434