mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
config: create a copy of the section name
The parsing context keeps a pointer to the current section name. This is used when logging errors. However, the pointer was into a buffer allocated by getline(). This buffer are often re-used in the next call to getline(), or free:d. Regardless, the section name pointer is invalid after the next call to getline(), which meant all error messages were logging a correct section name.
This commit is contained in:
parent
43798685d8
commit
9b232e07f9
2 changed files with 9 additions and 2 deletions
|
|
@ -49,6 +49,7 @@
|
|||
|
||||
* Regression: `letter-spacing` resulting in a “not a valid option”
|
||||
error (https://codeberg.org/dnkl/foot/issues/795).
|
||||
* Regression: bad section name in configuration error messages.
|
||||
|
||||
|
||||
### Security
|
||||
|
|
|
|||
10
config.c
10
config.c
|
|
@ -2469,9 +2469,11 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar
|
|||
continue; \
|
||||
}
|
||||
|
||||
char *section_name = xstrdup("main");
|
||||
|
||||
struct context context = {
|
||||
.conf = conf,
|
||||
.section = "main",
|
||||
.section = section_name,
|
||||
.path = path,
|
||||
.lineno = 0,
|
||||
.errors_are_fatal = errors_are_fatal,
|
||||
|
|
@ -2539,7 +2541,9 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar
|
|||
error_or_continue();
|
||||
}
|
||||
|
||||
context.section = &key_value[1];
|
||||
free(section_name);
|
||||
section_name = xstrdup(&key_value[1]);
|
||||
context.section = section_name;
|
||||
|
||||
/* Process next line */
|
||||
continue;
|
||||
|
|
@ -2569,10 +2573,12 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar
|
|||
error_or_continue();
|
||||
}
|
||||
|
||||
free(section_name);
|
||||
free(_line);
|
||||
return true;
|
||||
|
||||
err:
|
||||
free(section_name);
|
||||
free(_line);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue