Fixes from security review

Thanks to csteipp!

Change-Id: I2b711c4185103075cf665d61af3a6adc4446dcef