config: remove unneeded struct field
As well as receiving the config key and value, config callbacks also receive a "struct key_value_info" containing information about the source of the key-value pair. Accessing the "path" field of this struct from a callback passed to repo_config() results in a use-after-free. This happens because repo_config() first populates a configset by calling config_with_options() and then iterates over the configset with the callback passed by the caller. When the configset is constructed it takes a shallow copy of the "struct key_value_info" for each config setting. This leads to the use-after-free as the "path" member is freed before config_with_options() returns. We could fix this by interning the "path" field as we do for the "filename" field but the "path" field is not actually needed. It is populated with a copy of the "path" field from "struct config_source". That field was added ind14d42440d(config: disallow relative include paths from blobs, 2014-02-19) to distinguish between relative include directives in files and those in blobs. However, since1b8132d99d(i18n: config: unfold error messages marked for translation, 2016-07-28) we can differentiate these by looking at the "origin_type" field in "struct key_value_info". So let's remove the "path" members from "struct config_source" and "struct key_value_info" and instead use a combination of the "filename" and "origin_type" fields to determine the absolute path of relative includes. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
16bd9f20a4
commit
14d7583beb
2
config.h
2
config.h
@@ -122,14 +122,12 @@ struct key_value_info {
|
||||
int linenr;
|
||||
enum config_origin_type origin_type;
|
||||
enum config_scope scope;
|
||||
const char *path;
|
||||
};
|
||||
#define KVI_INIT { \
|
||||
.filename = NULL, \
|
||||
.linenr = -1, \
|
||||
.origin_type = CONFIG_ORIGIN_UNKNOWN, \
|
||||
.scope = CONFIG_SCOPE_UNKNOWN, \
|
||||
.path = NULL, \
|
||||
}
|
||||
|
||||
/* Captures additional information that a config callback can use. */
|
||||
|
||||
Reference in New Issue
Block a user