config-set: check write-in-full returns in set_multivar
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 11, 2007 at 13:16 UTC
93c1e07947e83f13fa8f1c89cb4897b5c71459ff
1 file changed
+24
-19
config.c
+24
-19
@@ -694,11 +694,9 @@ int git_config_set_multivar(const char* key, const char* value,
694
695
store.key = (char*)key;
696
if (!store_write_section(fd, key) ||
697
- !store_write_pair(fd, key, value)) {
698
- ret = write_error();
699
- goto out_free;
700
- }
701
- } else{
697
+ !store_write_pair(fd, key, value))
698
+ goto write_err_out;
699
+ } else {
700
struct stat st;
701
char* contents;
702
int i, copy_begin, copy_end, new_line = 0;
@@ -777,31 +775,33 @@ int git_config_set_multivar(const char* key, const char* value,
775
776
/* write the first part of the config */
777
if (copy_end > copy_begin) {
780
- write_in_full(fd, contents + copy_begin,
781
- copy_end - copy_begin);
782
- if (new_line)
783
- write_in_full(fd, "\n", 1);
778
+ if (write_in_full(fd, contents + copy_begin,
779
+ copy_end - copy_begin) <
780
+ copy_end - copy_begin)
781
+ goto write_err_out;
782
+ if (new_line &&
783
+ write_in_full(fd, "\n", 1) != 1)
784
+ goto write_err_out;
785
}
786
copy_begin = store.offset[i];
787
}
788
789
/* write the pair (value == NULL means unset) */
790
if (value != NULL) {
790
- if (store.state == START)
791
- if (!store_write_section(fd, key)) {
792
- ret = write_error();
793
- goto out_free;
794
- }
795
- if (!store_write_pair(fd, key, value)) {
796
- ret = write_error();
797
- goto out_free;
791
+ if (store.state == START) {
792
+ if (!store_write_section(fd, key))
793
+ goto write_err_out;
794
}
795
+ if (!store_write_pair(fd, key, value))
796
+ goto write_err_out;
797
}
798
799
/* write the rest of the config */
800
if (copy_begin < st.st_size)
803
- write_in_full(fd, contents + copy_begin,
804
- st.st_size - copy_begin);
801
+ if (write_in_full(fd, contents + copy_begin,
802
+ st.st_size - copy_begin) <
803
+ st.st_size - copy_begin)
804
+ goto write_err_out;
805
806
munmap(contents, st.st_size);
807
unlink(config_filename);
@@ -824,6 +824,11 @@ out_free:
824
free(lock_file);
825
}
826
return ret;
827
+
828
+write_err_out:
829
+ ret = write_error();
830
+ goto out_free;
831
+
832
}
833
834
int git_config_rename_section(const char *old_name, const char *new_name)