Skip to content
Snippets Groups Projects
Commit 78a840ed authored by derf's avatar derf Committed by GitHub
Browse files

Merge pull request #287 from stoeckmann/empty-file

Avoid out of boundary read on empty/broken file.
parents 1e042038 bdee6af0
No related branches found
No related tags found
No related merge requests found
......@@ -183,14 +183,14 @@ char *ereadfile(char *path)
{
char buffer[4096];
FILE *fp;
int count;
size_t count;
fp = fopen(path, "r");
if (!fp)
return NULL;
count = fread(buffer, sizeof(char), sizeof(buffer) - 1, fp);
if (buffer[count - 1] == '\n')
if (count > 0 && buffer[count - 1] == '\n')
buffer[count - 1] = '\0';
else
buffer[count] = '\0';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment