未验证 提交 2c59c5ea 编写于 作者: Y Yu Dou 提交者: GitHub

fixed heap-buffer-overflow (#116)

上级 ecd235de
...@@ -72,6 +72,8 @@ int readFromFile(const std::string &fileName, char *&outputData, size_t &fileSiz ...@@ -72,6 +72,8 @@ int readFromFile(const std::string &fileName, char *&outputData, size_t &fileSiz
fclose(file); fclose(file);
data = (char *)lrealloc(data, readSize + 1);
data[readSize] = '\0';
outputData = data; outputData = data;
fileSize = readSize; fileSize = readSize;
return 0; return 0;
......
...@@ -30,8 +30,7 @@ int main() ...@@ -30,8 +30,7 @@ int main()
std::string pidFile = getPidPath(); std::string pidFile = getPidPath();
char buf[1024] = {0}; char *p = NULL;
char *p = buf;
size_t size = 0; size_t size = 0;
readFromFile(pidFile, p, size); readFromFile(pidFile, p, size);
...@@ -39,5 +38,7 @@ int main() ...@@ -39,5 +38,7 @@ int main()
long long target = 0; long long target = 0;
str_to_val(temp, target); str_to_val(temp, target);
free(p);
EXPECT_EQ(pid, target); EXPECT_EQ(pid, target);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册