Fix buffer overflow error by only supplying st_size to fread once
This commit is contained in:
parent
47406b5def
commit
2b3c39d18c
3
Makefile
3
Makefile
|
@ -3,10 +3,9 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0
|
# SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
wai: wai.c
|
wai: wai.c
|
||||||
gcc -Wall -Wextra -o wai wai.c
|
gcc -ggdb -Wall -Wextra -o wai wai.c
|
||||||
|
|
||||||
# tests/factorial.wasm: tests/factorial.wat
|
# tests/factorial.wasm: tests/factorial.wat
|
||||||
.PHONY: tests
|
.PHONY: tests
|
||||||
tests:
|
tests:
|
||||||
wat2wasm -o tests/factorial.wasm tests/factorial.wat
|
wat2wasm -o tests/factorial.wasm tests/factorial.wat
|
||||||
|
|
||||||
|
|
3
wai.c
3
wai.c
|
@ -338,7 +338,6 @@ int parse_module(u_char *binary, size_t len) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
|
@ -356,7 +355,7 @@ int main(int argc, char **argv) {
|
||||||
printf("size: %ld\n", st.st_size);
|
printf("size: %ld\n", st.st_size);
|
||||||
|
|
||||||
unsigned char *binary = malloc(st.st_size);
|
unsigned char *binary = malloc(st.st_size);
|
||||||
fread(binary, st.st_size, st.st_size, file);
|
fread(binary, st.st_size, 1, file);
|
||||||
|
|
||||||
if (parse_module(binary, st.st_size) == -1) {
|
if (parse_module(binary, st.st_size) == -1) {
|
||||||
printf("error :(\n");
|
printf("error :(\n");
|
||||||
|
|
Loading…
Reference in a new issue