parse_config_key(): return subsection len as size_t
We return the length to a subset of a string using an "int *" out-parameter. This is fine most of the time, as we'd expect config keys to be relatively short, but it could behave oddly if we had a gigantic config key. A more appropriate type is size_t. Let's switch over, which lets our callers use size_t as appropriate (they are bound by our type because they must pass the out-parameter as a pointer). This is mostly just a cleanup to make it clear this code handles long strings correctly. In practice, our config parser already chokes on long key names (because of a similar int/size_t mixup!). When doing an int/size_t conversion, we have to be careful that nobody was trying to assign a negative value to the variable. I manually confirmed that for each case here. They tend to just feed the result to xmemdupz() or similar; in a few cases I adjusted the parameter types for helper functions to make sure the size_t is preserved. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
021ba32a7b
commit
f5914f4b6b
@ -364,7 +364,7 @@ static struct archiver **tar_filters;
|
||||
static int nr_tar_filters;
|
||||
static int alloc_tar_filters;
|
||||
|
||||
static struct archiver *find_tar_filter(const char *name, int len)
|
||||
static struct archiver *find_tar_filter(const char *name, size_t len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < nr_tar_filters; i++) {
|
||||
@ -380,7 +380,7 @@ static int tar_filter_config(const char *var, const char *value, void *data)
|
||||
struct archiver *ar;
|
||||
const char *name;
|
||||
const char *type;
|
||||
int namelen;
|
||||
size_t namelen;
|
||||
|
||||
if (parse_config_key(var, "tar", &name, &namelen, &type) < 0 || !name)
|
||||
return 0;
|
||||
|
@ -242,7 +242,7 @@ static int add_man_viewer_cmd(const char *name,
|
||||
static int add_man_viewer_info(const char *var, const char *value)
|
||||
{
|
||||
const char *name, *subkey;
|
||||
int namelen;
|
||||
size_t namelen;
|
||||
|
||||
if (parse_config_key(var, "man", &name, &namelen, &subkey) < 0 || !name)
|
||||
return 0;
|
||||
|
@ -459,7 +459,7 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
|
||||
static int reflog_expire_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
const char *pattern, *key;
|
||||
int pattern_len;
|
||||
size_t pattern_len;
|
||||
timestamp_t expire;
|
||||
int slot;
|
||||
struct reflog_expire_cfg *ent;
|
||||
|
4
config.c
4
config.c
@ -309,7 +309,7 @@ int git_config_include(const char *var, const char *value, void *data)
|
||||
{
|
||||
struct config_include_data *inc = data;
|
||||
const char *cond, *key;
|
||||
int cond_len;
|
||||
size_t cond_len;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@ -3238,7 +3238,7 @@ int config_error_nonbool(const char *var)
|
||||
|
||||
int parse_config_key(const char *var,
|
||||
const char *section,
|
||||
const char **subsection, int *subsection_len,
|
||||
const char **subsection, size_t *subsection_len,
|
||||
const char **key)
|
||||
{
|
||||
const char *dot;
|
||||
|
2
config.h
2
config.h
@ -359,7 +359,7 @@ int git_config_include(const char *name, const char *value, void *data);
|
||||
*/
|
||||
int parse_config_key(const char *var,
|
||||
const char *section,
|
||||
const char **subsection, int *subsection_len,
|
||||
const char **subsection, size_t *subsection_len,
|
||||
const char **key);
|
||||
|
||||
/**
|
||||
|
@ -1018,7 +1018,7 @@ static int apply_filter(const char *path, const char *src, size_t len,
|
||||
static int read_convert_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
const char *key, *name;
|
||||
int namelen;
|
||||
size_t namelen;
|
||||
struct convert_driver *drv;
|
||||
|
||||
/*
|
||||
|
2
fsck.c
2
fsck.c
@ -920,7 +920,7 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
|
||||
{
|
||||
struct fsck_gitmodules_data *data = vdata;
|
||||
const char *subsection, *key;
|
||||
int subsection_len;
|
||||
size_t subsection_len;
|
||||
char *name;
|
||||
|
||||
if (parse_config_key(var, "submodule", &subsection, &subsection_len, &key) < 0 ||
|
||||
|
@ -247,7 +247,7 @@ static int read_merge_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
struct ll_merge_driver *fn;
|
||||
const char *key, *name;
|
||||
int namelen;
|
||||
size_t namelen;
|
||||
|
||||
if (!strcmp(var, "merge.default"))
|
||||
return git_config_string(&default_ll_merge, var, value);
|
||||
|
@ -101,7 +101,7 @@ static void promisor_remote_move_to_tail(struct promisor_remote *r,
|
||||
static int promisor_remote_config(const char *var, const char *value, void *data)
|
||||
{
|
||||
const char *name;
|
||||
int namelen;
|
||||
size_t namelen;
|
||||
const char *subkey;
|
||||
|
||||
if (!strcmp(var, "core.partialclonefilter"))
|
||||
|
2
remote.c
2
remote.c
@ -305,7 +305,7 @@ static void read_branches_file(struct remote *remote)
|
||||
static int handle_config(const char *key, const char *value, void *cb)
|
||||
{
|
||||
const char *name;
|
||||
int namelen;
|
||||
size_t namelen;
|
||||
const char *subkey;
|
||||
struct remote *remote;
|
||||
struct branch *branch;
|
||||
|
@ -225,7 +225,8 @@ static int name_and_item_from_var(const char *var, struct strbuf *name,
|
||||
struct strbuf *item)
|
||||
{
|
||||
const char *subsection, *key;
|
||||
int subsection_len, parse;
|
||||
size_t subsection_len;
|
||||
int parse;
|
||||
parse = parse_config_key(var, "submodule", &subsection,
|
||||
&subsection_len, &key);
|
||||
if (parse < 0 || !subsection)
|
||||
|
@ -222,7 +222,7 @@ static struct userdiff_driver driver_false = {
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
static struct userdiff_driver *userdiff_find_by_namelen(const char *k, int len)
|
||||
static struct userdiff_driver *userdiff_find_by_namelen(const char *k, size_t len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < ndrivers; i++) {
|
||||
@ -266,7 +266,7 @@ int userdiff_config(const char *k, const char *v)
|
||||
{
|
||||
struct userdiff_driver *drv;
|
||||
const char *name, *type;
|
||||
int namelen;
|
||||
size_t namelen;
|
||||
|
||||
if (parse_config_key(k, "diff", &name, &namelen, &type) || !name)
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user