зеркало из https://github.com/microsoft/git.git
Merge branch 'nd/config-misc-fixes' into maint
Leakage of lockfiles in the config subsystem has been fixed. * nd/config-misc-fixes: config.c: handle lock file in error case in git_config_rename_... config.c: rename label unlock_and_out config.c: handle error case for fstat() calls
This commit is contained in:
Коммит
bb7c47a452
20
config.c
20
config.c
|
@ -2216,7 +2216,12 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
|
|||
goto out_free;
|
||||
}
|
||||
|
||||
fstat(in_fd, &st);
|
||||
if (fstat(in_fd, &st) == -1) {
|
||||
error_errno(_("fstat on %s failed"), config_filename);
|
||||
ret = CONFIG_INVALID_FILE;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
contents_sz = xsize_t(st.st_size);
|
||||
contents = xmmap_gently(NULL, contents_sz, PROT_READ,
|
||||
MAP_PRIVATE, in_fd, 0);
|
||||
|
@ -2418,7 +2423,7 @@ int git_config_rename_section_in_file(const char *config_filename,
|
|||
|
||||
if (new_name && !section_name_is_ok(new_name)) {
|
||||
ret = error("invalid section name: %s", new_name);
|
||||
goto out;
|
||||
goto out_no_rollback;
|
||||
}
|
||||
|
||||
if (!config_filename)
|
||||
|
@ -2433,10 +2438,13 @@ int git_config_rename_section_in_file(const char *config_filename,
|
|||
|
||||
if (!(config_file = fopen(config_filename, "rb"))) {
|
||||
/* no config file means nothing to rename, no error */
|
||||
goto unlock_and_out;
|
||||
goto commit_and_out;
|
||||
}
|
||||
|
||||
fstat(fileno(config_file), &st);
|
||||
if (fstat(fileno(config_file), &st) == -1) {
|
||||
ret = error_errno(_("fstat on %s failed"), config_filename);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
|
||||
ret = error_errno("chmod on %s failed",
|
||||
|
@ -2492,11 +2500,13 @@ int git_config_rename_section_in_file(const char *config_filename,
|
|||
}
|
||||
}
|
||||
fclose(config_file);
|
||||
unlock_and_out:
|
||||
commit_and_out:
|
||||
if (commit_lock_file(lock) < 0)
|
||||
ret = error_errno("could not write config file %s",
|
||||
config_filename);
|
||||
out:
|
||||
rollback_lock_file(lock);
|
||||
out_no_rollback:
|
||||
free(filename_buf);
|
||||
return ret;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче