Skip to content

Commit

Permalink
correct cocos2d#18768, add check for unsafe strcpy() (cocos2d#18885)
Browse files Browse the repository at this point in the history
* add check for unsafe strcpy()

add check for unsafe strcpy()

* complying with required coding style

substitute tab with 4 spaces

* NULL -> nullptr
  • Loading branch information
drelaptop authored Jun 8, 2018
1 parent 702fc83 commit b26e1bb
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,18 @@ void LuaMinXmlHttpRequest::_setHttpRequestHeader()
const char* second = it->second.c_str();
size_t len = sizeof(char) * (strlen(first) + 3 + strlen(second));
char* test = (char*) malloc(len);
memset(test, 0,len);
if (test != nullptr) //should check failure of malloc or it could be an undefined behaviour
{
memset(test, 0,len);

strcpy(test, first);
strcpy(test + strlen(first) , ": ");
strcpy(test + strlen(first) + 2, second);
strcpy(test, first);
strcpy(test + strlen(first) , ": ");
strcpy(test + strlen(first) + 2, second);

header.push_back(test);
header.push_back(test);

free(test);
free(test);
}

}

Expand Down

0 comments on commit b26e1bb

Please sign in to comment.