Check asprintf() return value.

This commit is contained in:
Todd C. Miller
2020-06-06 19:13:21 -06:00
parent a339945848
commit 3e12b99eed

View File

@@ -255,13 +255,17 @@ int
mock_python_datetime_now(const char *plugin_name, const char *date_str)
{
char *cmd = NULL;
asprintf(&cmd, "import %s\n" // the plugin has its own submodule
int len;
len = asprintf(&cmd,
"import %s\n" // the plugin has its own submodule
"from datetime import datetime\n" // store the real datetime
"import time\n"
"from unittest.mock import Mock\n"
"%s.datetime = Mock()\n" // replace plugin's datetime
"%s.datetime.now = lambda: datetime.strptime('%s', '%%Y-%%m-%%dT%%H:%%M:%%S')\n",
plugin_name, plugin_name, plugin_name, date_str);
if (len == -1)
return false;
VERIFY_PTR_NE(cmd, NULL);
VERIFY_INT(PyRun_SimpleString(cmd), 0);
free(cmd);