Skip to content

Commit

Permalink
yomidbbuilder: fixes crash when attempting to add an invalid dictionary
Browse files Browse the repository at this point in the history
libzip's zip_fclose() function does not no-op on NULL, so a check needs
to be performed outside the function.
  • Loading branch information
ripose-jp committed Mar 23, 2022
1 parent 8870190 commit 446210e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/dict/yomidbbuilder.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ static int get_json_obj(zip_t *archive, const char *filename, json_object **obj)

cleanup:
free(contents);
zip_fclose(file);
if (file)
{
zip_fclose(file);
}

return ret;
}
Expand Down Expand Up @@ -1817,7 +1820,10 @@ static int extract_resources(zip_t *dict_archive, const char *res_dir)
{
fprintf(stderr, "Could not open file for writing\n%s\n", file_path);
free(file_path);
zip_fclose(zip_file);
if (zip_file)
{
zip_fclose(zip_file);
}
goto cleanup;
}
free(file_path);
Expand All @@ -1831,7 +1837,10 @@ static int extract_resources(zip_t *dict_archive, const char *res_dir)
fwrite(buf, sizeof(char), bytes_read, file);
}
fclose(file);
zip_fclose(zip_file);
if (zip_file)
{
zip_fclose(zip_file);
}
}

cleanup:
Expand Down

0 comments on commit 446210e

Please sign in to comment.