mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-05 05:48:29 +00:00
remote: don't write too much when dealing with multivars
We used to move `data_start` forward, which is wrong as that needs to point to the beginning of the buffer in order to perform size calculations. Introduce a `write_start` variable which indicates where we should start writing from, which is what the `data_start` was being wrongly reused to be.
This commit is contained in:
parent
187009e253
commit
a7a64d2cad
@ -1185,7 +1185,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|||||||
{
|
{
|
||||||
int result, c;
|
int result, c;
|
||||||
int section_matches = 0, last_section_matched = 0, preg_replaced = 0, write_trailer = 0;
|
int section_matches = 0, last_section_matched = 0, preg_replaced = 0, write_trailer = 0;
|
||||||
const char *pre_end = NULL, *post_start = NULL, *data_start;
|
const char *pre_end = NULL, *post_start = NULL, *data_start, *write_start;
|
||||||
char *current_section = NULL, *section, *name, *ldot;
|
char *current_section = NULL, *section, *name, *ldot;
|
||||||
git_filebuf file = GIT_FILEBUF_INIT;
|
git_filebuf file = GIT_FILEBUF_INIT;
|
||||||
struct reader *reader = git_array_get(cfg->readers, 0);
|
struct reader *reader = git_array_get(cfg->readers, 0);
|
||||||
@ -1207,6 +1207,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|||||||
return -1; /* OS error when reading the file */
|
return -1; /* OS error when reading the file */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write_start = data_start;
|
||||||
|
|
||||||
/* Lock the file */
|
/* Lock the file */
|
||||||
if (git_filebuf_open(&file, cfg->file_path, 0) < 0)
|
if (git_filebuf_open(&file, cfg->file_path, 0) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -1291,7 +1293,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|||||||
|
|
||||||
/* We've found the variable we wanted to change, so
|
/* We've found the variable we wanted to change, so
|
||||||
* write anything up to it */
|
* write anything up to it */
|
||||||
git_filebuf_write(&file, data_start, pre_end - data_start);
|
git_filebuf_write(&file, write_start, pre_end - write_start);
|
||||||
preg_replaced = 1;
|
preg_replaced = 1;
|
||||||
|
|
||||||
/* Then replace the variable. If the value is NULL, it
|
/* Then replace the variable. If the value is NULL, it
|
||||||
@ -1300,9 +1302,13 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|||||||
git_filebuf_printf(&file, "\t%s = %s\n", name, value);
|
git_filebuf_printf(&file, "\t%s = %s\n", name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* multiline variable? we need to keep reading lines to match */
|
/*
|
||||||
if (preg != NULL && section_matches) {
|
* If we have a multivar, we should keep looking for entries,
|
||||||
data_start = post_start;
|
* but only if we're in the right section. Otherwise we'll end up
|
||||||
|
* looping on the edge of a matching and a non-matching section.
|
||||||
|
*/
|
||||||
|
if (section_matches && preg != NULL) {
|
||||||
|
write_start = post_start;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1332,7 +1338,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|||||||
git_filebuf_write(&file, post_start, reader->buffer.size - (post_start - data_start));
|
git_filebuf_write(&file, post_start, reader->buffer.size - (post_start - data_start));
|
||||||
} else {
|
} else {
|
||||||
if (preg_replaced) {
|
if (preg_replaced) {
|
||||||
git_filebuf_printf(&file, "\n%s", data_start);
|
git_filebuf_printf(&file, "\n%s", write_start);
|
||||||
} else {
|
} else {
|
||||||
git_filebuf_write(&file, reader->buffer.ptr, reader->buffer.size);
|
git_filebuf_write(&file, reader->buffer.ptr, reader->buffer.size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user