aboutsummaryrefslogtreecommitdiffstats
path: root/fuzz
diff options
context:
space:
mode:
authorTatsuya Kinoshita <tats@debian.org>2021-03-25 09:55:49 +0000
committerTatsuya Kinoshita <tats@debian.org>2021-03-25 09:55:49 +0000
commit5a1059b6f3ab031afa48c5ddcd81392444de53a9 (patch)
treefc6b03e17fac10683c4d092fb6b135ab5991bd5e /fuzz
parentUpdate ChangeLog (diff)
downloadw3m-5a1059b6f3ab031afa48c5ddcd81392444de53a9.tar.gz
w3m-5a1059b6f3ab031afa48c5ddcd81392444de53a9.zip
Prevent memory leak in fuzzer
Diffstat (limited to 'fuzz')
-rw-r--r--fuzz/fuzz-conv.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/fuzz/fuzz-conv.c b/fuzz/fuzz-conv.c
index 5414742..ae6d31f 100644
--- a/fuzz/fuzz-conv.c
+++ b/fuzz/fuzz-conv.c
@@ -9,7 +9,7 @@
char *get_null_terminated(const uint8_t *data, size_t size) {
char *new_str = (char *)malloc(size+1);
if (new_str == NULL){
- return NULL;
+ exit(1);
}
memcpy(new_str, data, size);
new_str[size] = '\0';
@@ -57,17 +57,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size){
sprintf(filename, "/tmp/libfuzzer.%d", getpid());
FILE *fp = fopen(filename, "wb");
- if (!fp) {
- return 0;
+ if (fp) {
+ fwrite(data, size, 1, fp);
+ fclose(fp);
}
- fwrite(data, size, 1, fp);
- fclose(fp);
FILE *f = fopen(filename, "r");
- Str s = Strfgetall(f);
- wc_Str_conv_with_detect(s, &from, from, to);
- if (s != NULL) {
- Strfree(s);
+ if (f) {
+ Str s = Strfgetall(f);
+ wc_Str_conv_with_detect(s, &from, from, to);
+ if (s != NULL) {
+ Strfree(s);
+ }
+ fclose(f);
}
unlink(filename);