Просмотр исходного кода

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 лет назад: 10
Родитель
Сommit
b7deef8a6c
1 измененных файлов с 1 добавлено и 1 удалено
  1. 1 1
      c/ton/main.c

+ 1 - 1
c/ton/main.c

217
		goto err;
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
	memset(buf, 0, f_stat.st_size);
221
	memset(buf, 0, f_stat.st_size);
222
	fread(buf, f_stat.st_size, 1, f);
222
	fread(buf, f_stat.st_size, 1, f);
223
	buf[f_stat.st_size] = '\0';
223
	buf[f_stat.st_size] = '\0';