]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config.c: handle error case for fstat() calls
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 19 Dec 2016 09:21:55 +0000 (16:21 +0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Dec 2016 20:08:06 +0000 (12:08 -0800)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c

index d7ce34b33d67c38245e77b7082d80f350e4f7eb7..19ceb2639ea236c660e215020ec99873eecea2c4 100644 (file)
--- a/config.c
+++ b/config.c
@@ -2107,7 +2107,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);
@@ -2327,7 +2332,10 @@ int git_config_rename_section_in_file(const char *config_filename,
                goto unlock_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",