Skip to content

Commit 7865d15

Browse files
Martin Ågrengitster
authored andcommitted
refspec: initalize refspec_item in valid_fetch_refspec()
We allocate a `struct refspec_item` on the stack without initializing it. In particular, its `dst` and `src` members will contain some random data from the stack. When we later call `refspec_item_clear()`, it will call `free()` on those pointers. So if the call to `parse_refspec()` did not assign to them, we will be freeing some random "pointers". This is undefined behavior. To the best of my understanding, this cannot currently be triggered by user-provided data. And for what it's worth, the test-suite does not trigger this with SANITIZE=address. It can be provoked by calling `valid_fetch_refspec(":*")`. Zero the struct, as is done in other users of `struct refspec_item` by using the refspec_item_init() initialization function. Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c495fd3 commit 7865d15

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

refspec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void refspec_clear(struct refspec *rs)
194194
int valid_fetch_refspec(const char *fetch_refspec_str)
195195
{
196196
struct refspec_item refspec;
197-
int ret = parse_refspec(&refspec, fetch_refspec_str, REFSPEC_FETCH);
197+
int ret = refspec_item_init(&refspec, fetch_refspec_str, REFSPEC_FETCH);
198198
refspec_item_clear(&refspec);
199199
return ret;
200200
}

0 commit comments

Comments
 (0)