Skip to content

Commit c113c5d

Browse files
pks-tgitster
authored andcommitted
global: convert intentionally-leaking config strings to consts
There are multiple cases where we intentionally leak config strings: - `struct gpg_format` is used to track programs that can be used for signing commits, either via gpg(1), gpgsm(1) or ssh-keygen(1). The user can override the commands via several config variables. As the array is populated once, only, and the struct memers are never written to or free'd. - `struct ll_merge_driver` is used to track merge drivers. Same as with the GPG format, these drivers are populated once and then reused. Its data is never written to or free'd, either. - `struct userdiff_funcname` and `struct userdiff_driver` can be configured via `diff.<driver>.*` to add additional drivers. Again, these have a global lifetime and are never written to or free'd. All of these are intentionally kept alive and are never written to. Furthermore, all of these are being assigned both string constants in some places, and allocated strings in other places. This will cause warnings once we enable `-Wwrite-strings`, so let's mark the respective fields as `const char *` and cast away the constness when assigning those values. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b567004 commit c113c5d

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

gpg-interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static enum signature_trust_level configured_min_trust_level = TRUST_UNDEFINED;
3434

3535
struct gpg_format {
3636
const char *name;
37-
char *program;
37+
const char *program;
3838
const char **verify_args;
3939
const char **sigs;
4040
int (*verify_signed_buffer)(struct signature_check *sigc,
@@ -783,7 +783,7 @@ static int git_gpg_config(const char *var, const char *value,
783783

784784
if (fmtname) {
785785
fmt = get_format_by_name(fmtname);
786-
return git_config_string(&fmt->program, var, value);
786+
return git_config_string((char **) &fmt->program, var, value);
787787
}
788788

789789
return 0;

merge-ll.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ typedef enum ll_merge_result (*ll_merge_fn)(const struct ll_merge_driver *,
2727

2828
struct ll_merge_driver {
2929
const char *name;
30-
char *description;
30+
const char *description;
3131
ll_merge_fn fn;
3232
char *recursive;
3333
struct ll_merge_driver *next;
@@ -304,8 +304,13 @@ static int read_merge_config(const char *var, const char *value,
304304
ll_user_merge_tail = &(fn->next);
305305
}
306306

307-
if (!strcmp("name", key))
308-
return git_config_string(&fn->description, var, value);
307+
if (!strcmp("name", key)) {
308+
/*
309+
* The description is leaking, but that's okay as we want to
310+
* keep around the merge drivers anyway.
311+
*/
312+
return git_config_string((char **) &fn->description, var, value);
313+
}
309314

310315
if (!strcmp("driver", key)) {
311316
if (!value)

userdiff.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static struct userdiff_driver *userdiff_find_by_namelen(const char *name, size_t
399399
static int parse_funcname(struct userdiff_funcname *f, const char *k,
400400
const char *v, int cflags)
401401
{
402-
if (git_config_string(&f->pattern, k, v) < 0)
402+
if (git_config_string((char **) &f->pattern, k, v) < 0)
403403
return -1;
404404
f->cflags = cflags;
405405
return 0;
@@ -445,15 +445,15 @@ int userdiff_config(const char *k, const char *v)
445445
if (!strcmp(type, "binary"))
446446
return parse_tristate(&drv->binary, k, v);
447447
if (!strcmp(type, "command"))
448-
return git_config_string(&drv->external, k, v);
448+
return git_config_string((char **) &drv->external, k, v);
449449
if (!strcmp(type, "textconv"))
450-
return git_config_string(&drv->textconv, k, v);
450+
return git_config_string((char **) &drv->textconv, k, v);
451451
if (!strcmp(type, "cachetextconv"))
452452
return parse_bool(&drv->textconv_want_cache, k, v);
453453
if (!strcmp(type, "wordregex"))
454-
return git_config_string(&drv->word_regex, k, v);
454+
return git_config_string((char **) &drv->word_regex, k, v);
455455
if (!strcmp(type, "algorithm"))
456-
return git_config_string(&drv->algorithm, k, v);
456+
return git_config_string((char **) &drv->algorithm, k, v);
457457

458458
return 0;
459459
}

userdiff.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ struct index_state;
77
struct repository;
88

99
struct userdiff_funcname {
10-
char *pattern;
10+
const char *pattern;
1111
int cflags;
1212
};
1313

1414
struct userdiff_driver {
1515
const char *name;
16-
char *external;
17-
char *algorithm;
16+
const char *external;
17+
const char *algorithm;
1818
int binary;
1919
struct userdiff_funcname funcname;
20-
char *word_regex;
21-
char *word_regex_multi_byte;
22-
char *textconv;
20+
const char *word_regex;
21+
const char *word_regex_multi_byte;
22+
const char *textconv;
2323
struct notes_cache *textconv_cache;
2424
int textconv_want_cache;
2525
};

0 commit comments

Comments
 (0)