Commit 61dcfe14 by Carlos Martín Nieto

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.
parent 5a49ff9f
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment