config.c: handle error case for fstat() calls
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Dec 19, 2016 at 16:21 UTC
29647d79a9a29498675ccb137f567a44dc9628b8
1 file changed
+10
-2
config.c
+10
-2
@@ -2107,7 +2107,12 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
2107
goto out_free;
2108
}
2109
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
+
2116
contents_sz = xsize_t(st.st_size);
2117
contents = xmmap_gently(NULL, contents_sz, PROT_READ,
2118
MAP_PRIVATE, in_fd, 0);
@@ -2327,7 +2332,10 @@ int git_config_rename_section_in_file(const char *config_filename,
2332
goto unlock_and_out;
2333
}
2334
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
+ }
2339
2340
if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
2341
ret = error_errno("chmod on %s failed",