Fix prevent issues
This commit fixes following prevent CIDs:
* 458876: Avoid copying string which cannot be null-terminated
* 459717: NULL-check after memory allocation
* 461686: NULL-check tainted scalar(string read by fgets())
* 462630: NULL-check after memory allocation
* 466499: NULL-check after memory allocation
* 470326: NULL-check after memory allocation
* 471806: NULL-check after memory allocation
* 472387: NULL-check after memory allocation
* 475993: NULL-check after memory allocation
Change-Id: Ie33494a2055528ae1c8b8ffb296a2111c3468e95