Skip to content

Commit

Permalink
config-set: check write-in-full returns in set_multivar
Browse files Browse the repository at this point in the history
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Jan 11, 2007
1 parent d1b2ddc commit 93c1e07
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,9 @@ int git_config_set_multivar(const char* key, const char* value,

store.key = (char*)key;
if (!store_write_section(fd, key) ||
!store_write_pair(fd, key, value)) {
ret = write_error();
goto out_free;
}
} else{
!store_write_pair(fd, key, value))
goto write_err_out;
} else {
struct stat st;
char* contents;
int i, copy_begin, copy_end, new_line = 0;
Expand Down Expand Up @@ -777,31 +775,33 @@ int git_config_set_multivar(const char* key, const char* value,

/* write the first part of the config */
if (copy_end > copy_begin) {
write_in_full(fd, contents + copy_begin,
copy_end - copy_begin);
if (new_line)
write_in_full(fd, "\n", 1);
if (write_in_full(fd, contents + copy_begin,
copy_end - copy_begin) <
copy_end - copy_begin)
goto write_err_out;
if (new_line &&
write_in_full(fd, "\n", 1) != 1)
goto write_err_out;
}
copy_begin = store.offset[i];
}

/* write the pair (value == NULL means unset) */
if (value != NULL) {
if (store.state == START)
if (!store_write_section(fd, key)) {
ret = write_error();
goto out_free;
}
if (!store_write_pair(fd, key, value)) {
ret = write_error();
goto out_free;
if (store.state == START) {
if (!store_write_section(fd, key))
goto write_err_out;
}
if (!store_write_pair(fd, key, value))
goto write_err_out;
}

/* write the rest of the config */
if (copy_begin < st.st_size)
write_in_full(fd, contents + copy_begin,
st.st_size - copy_begin);
if (write_in_full(fd, contents + copy_begin,
st.st_size - copy_begin) <
st.st_size - copy_begin)
goto write_err_out;

munmap(contents, st.st_size);
unlink(config_filename);
Expand All @@ -824,6 +824,11 @@ int git_config_set_multivar(const char* key, const char* value,
free(lock_file);
}
return ret;

write_err_out:
ret = write_error();
goto out_free;

}

int git_config_rename_section(const char *old_name, const char *new_name)
Expand Down

0 comments on commit 93c1e07

Please sign in to comment.