mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 09:36:47 +00:00
remote: make sure the name stays valid on rename
We must make sure that the name pointer remains valid, so make sure to allocate the new one before freeing the old one and swap them so the user never sees an invalid pointer.
This commit is contained in:
parent
5a49ff9fa0
commit
61dcfe1400
@ -1484,6 +1484,7 @@ int git_remote_rename(
|
||||
void *payload)
|
||||
{
|
||||
int error;
|
||||
char *tmp, *dup;
|
||||
|
||||
assert(remote && new_name);
|
||||
|
||||
@ -1510,10 +1511,12 @@ int git_remote_rename(
|
||||
if ((error = rename_fetch_refspecs(remote, new_name, callback, payload)) < 0)
|
||||
return error;
|
||||
|
||||
git__free(remote->name);
|
||||
dup = git__strdup(new_name);
|
||||
GITERR_CHECK_ALLOC(dup);
|
||||
|
||||
remote->name = git__strdup(new_name);
|
||||
GITERR_CHECK_ALLOC(remote->name);
|
||||
tmp = remote->name;
|
||||
remote->name = dup;
|
||||
git__free(tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user