Skip to content

Commit bb7c47a

Browse files
committed
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
2 parents 46ab222 + c06fa62 commit bb7c47a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

config.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,7 +2216,12 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
22162216
goto out_free;
22172217
}
22182218

2219-
fstat(in_fd, &st);
2219+
if (fstat(in_fd, &st) == -1) {
2220+
error_errno(_("fstat on %s failed"), config_filename);
2221+
ret = CONFIG_INVALID_FILE;
2222+
goto out_free;
2223+
}
2224+
22202225
contents_sz = xsize_t(st.st_size);
22212226
contents = xmmap_gently(NULL, contents_sz, PROT_READ,
22222227
MAP_PRIVATE, in_fd, 0);
@@ -2418,7 +2423,7 @@ int git_config_rename_section_in_file(const char *config_filename,
24182423

24192424
if (new_name && !section_name_is_ok(new_name)) {
24202425
ret = error("invalid section name: %s", new_name);
2421-
goto out;
2426+
goto out_no_rollback;
24222427
}
24232428

24242429
if (!config_filename)
@@ -2433,10 +2438,13 @@ int git_config_rename_section_in_file(const char *config_filename,
24332438

24342439
if (!(config_file = fopen(config_filename, "rb"))) {
24352440
/* no config file means nothing to rename, no error */
2436-
goto unlock_and_out;
2441+
goto commit_and_out;
24372442
}
24382443

2439-
fstat(fileno(config_file), &st);
2444+
if (fstat(fileno(config_file), &st) == -1) {
2445+
ret = error_errno(_("fstat on %s failed"), config_filename);
2446+
goto out;
2447+
}
24402448

24412449
if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
24422450
ret = error_errno("chmod on %s failed",
@@ -2492,11 +2500,13 @@ int git_config_rename_section_in_file(const char *config_filename,
24922500
}
24932501
}
24942502
fclose(config_file);
2495-
unlock_and_out:
2503+
commit_and_out:
24962504
if (commit_lock_file(lock) < 0)
24972505
ret = error_errno("could not write config file %s",
24982506
config_filename);
24992507
out:
2508+
rollback_lock_file(lock);
2509+
out_no_rollback:
25002510
free(filename_buf);
25012511
return ret;
25022512
}

0 commit comments

Comments
 (0)