avoid out of bounds string access

Change-Id: I0a0affea08528fc9bd729ab01cdb5fa6e9f8e18f
(cherry picked from commit 8c0bb201382d839124fb9a9c8906e2c2018a6939)