Fix issues detected by Coverity (#1154)

wasm_c_api.c: add more checks, fix LOG_WARNING invalid specifier
aot_emit_aot_file: fix strncpy max size length to copy
posix.c: fix potential socket not close issue
wasm-c-api samples: add return value checks for fseek/ftell
cJSON.c: remove dead code
This commit is contained in:
liang.he
2022-05-07 18:53:02 +08:00
committed by GitHub
parent 21e59d883f
commit ed512c6867
15 changed files with 294 additions and 98 deletions

View File

@ -77,9 +77,28 @@ int main(int argc, const char* argv[]) {
printf("> Error loading module!\n");
return 1;
}
fseek(file, 0L, SEEK_END);
size_t file_size = ftell(file);
fseek(file, 0L, SEEK_SET);
int ret = fseek(file, 0L, SEEK_END);
if (ret == -1) {
printf("> Error loading module!\n");
fclose(file);
return 1;
}
long file_size = ftell(file);
if (file_size == -1) {
printf("> Error loading module!\n");
fclose(file);
return 1;
}
ret = fseek(file, 0L, SEEK_SET);
if (ret == -1) {
printf("> Error loading module!\n");
fclose(file);
return 1;
}
wasm_byte_vec_t binary;
wasm_byte_vec_new_uninitialized(&binary, file_size);
if (fread(binary.data, file_size, 1, file) != 1) {