cleanups and sanity check string length

Change-Id: I17be8f06edd5ec507ab9b0a14cf305be75afc067
Add missing NULL sentinel.

Change-Id: I95b86d8e60d54a54280dae89ab93ff7eb322fe18