Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61dcfe1

Browse files
committed
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.
1 parent 5a49ff9 commit 61dcfe1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/remote.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,7 @@ int git_remote_rename(
14841484
void *payload)
14851485
{
14861486
int error;
1487+
char *tmp, *dup;
14871488

14881489
assert(remote && new_name);
14891490

@@ -1510,10 +1511,12 @@ int git_remote_rename(
15101511
if ((error = rename_fetch_refspecs(remote, new_name, callback, payload)) < 0)
15111512
return error;
15121513

1513-
git__free(remote->name);
1514+
dup = git__strdup(new_name);
1515+
GITERR_CHECK_ALLOC(dup);
15141516

1515-
remote->name = git__strdup(new_name);
1516-
GITERR_CHECK_ALLOC(remote->name);
1517+
tmp = remote->name;
1518+
remote->name = dup;
1519+
git__free(tmp);
15171520

15181521
return 0;
15191522
}

0 commit comments

Comments
 (0)