commit 2b3c39d18c4c751d36a0904f00efbf015fda7d4b
parent 47406b5defae9d4ec6a94aeee9454514d835d42b
Author: CSDUMMI <csdummi.misquality@simplelogin.co>
Date: Sat, 10 May 2025 18:42:55 +0200
Fix buffer overflow error by only supplying st_size to fread once
Diffstat:
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
@@ -3,10 +3,9 @@
# SPDX-License-Identifier: GPL-3.0
wai: wai.c
- gcc -Wall -Wextra -o wai wai.c
+ gcc -ggdb -Wall -Wextra -o wai wai.c
# tests/factorial.wasm: tests/factorial.wat
.PHONY: tests
tests:
wat2wasm -o tests/factorial.wasm tests/factorial.wat
-
diff --git a/wai.c b/wai.c
@@ -338,7 +338,6 @@ int parse_module(u_char *binary, size_t len) {
return i;
}
-
int main(int argc, char **argv) {
if (argc != 2) {
@@ -356,7 +355,7 @@ int main(int argc, char **argv) {
printf("size: %ld\n", 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) {
printf("error :(\n");