Skip to content

Commit 29647d7

Browse files
pcloudsgitster
authored andcommitted
config.c: handle error case for fstat() calls
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0202c41 commit 29647d7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

config.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,12 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
21072107
goto out_free;
21082108
}
21092109

2110-
fstat(in_fd, &st);
2110+
if (fstat(in_fd, &st) == -1) {
2111+
error_errno(_("fstat on %s failed"), config_filename);
2112+
ret = CONFIG_INVALID_FILE;
2113+
goto out_free;
2114+
}
2115+
21112116
contents_sz = xsize_t(st.st_size);
21122117
contents = xmmap_gently(NULL, contents_sz, PROT_READ,
21132118
MAP_PRIVATE, in_fd, 0);
@@ -2327,7 +2332,10 @@ int git_config_rename_section_in_file(const char *config_filename,
23272332
goto unlock_and_out;
23282333
}
23292334

2330-
fstat(fileno(config_file), &st);
2335+
if (fstat(fileno(config_file), &st) == -1) {
2336+
ret = error_errno(_("fstat on %s failed"), config_filename);
2337+
goto out;
2338+
}
23312339

23322340
if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
23332341
ret = error_errno("chmod on %s failed",

0 commit comments

Comments
 (0)