Skip to content

Commit 796fbb9

Browse files
committed
fix: add defensive NULL checks on this_link in Cache_create
Add a check for `this_link` returning NULL immediately in `Cache_create`, and guard the trailing `LinkTable_unref` call to prevent potential segmentation faults in case the path cannot be resolved.
1 parent af4ee30 commit 796fbb9

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/cache.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,9 @@ static void Meta_create(Cache *cf)
724724
int Cache_create(const char *path)
725725
{
726726
Link *this_link = path_to_Link(path);
727+
if (!this_link) {
728+
return 1;
729+
}
727730

728731
char *fn;
729732

@@ -782,7 +785,9 @@ int Cache_create(const char *path)
782785
curl_free(fn);
783786
}
784787

785-
LinkTable_unref(this_link->parent_table);
788+
if (this_link) {
789+
LinkTable_unref(this_link->parent_table);
790+
}
786791

787792
return res;
788793
}

0 commit comments

Comments
 (0)