浏览代码

Fix a segfault in get_contents

We would set the last element of the buffer to zero, just to be sure,
but wouldn't allocate that much memory, thus getting a segfault.
Lucas Stadler 9 年之前
父节点
当前提交
b7deef8a6c
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      c/ton/main.c

+ 1 - 1
c/ton/main.c

@ -217,7 +217,7 @@ char *get_contents(char *path) {
217 217
		goto err;
218 218
	}
219 219
220
	char *buf = malloc(f_stat.st_size);
220
	char *buf = malloc(f_stat.st_size + 1);
221 221
	memset(buf, 0, f_stat.st_size);
222 222
	fread(buf, f_stat.st_size, 1, f);
223 223
	buf[f_stat.st_size] = '\0';