Przeglądaj źródła

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 lat temu
rodzic
commit
b7deef8a6c
1 zmienionych plików z 1 dodań i 1 usunięć
  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';