diff_tform: fix potential NULL pointer access

The `normalize_find_opts` function in theory allows for the
incoming diff to have no repository. When the caller does not
pass in diff find options or if the GIT_DIFF_FIND_BY_CONFIG value
is set, though, we try to derive the configuration from the
diff's repository configuration without first verifying that the
repository is actually set to a non-NULL value.

Fix this issue by explicitly checking if the repository is set
and if it is not, fall back to a default value of
GIT_DIFF_FIND_RENAMES.
This commit is contained in:
Patrick Steinhardt 2016-02-23 11:07:03 +01:00
parent 3d1abc5afc
commit 32f0798413

View File

@ -261,18 +261,23 @@ static int normalize_find_opts(
if (!given || if (!given ||
(given->flags & GIT_DIFF_FIND_ALL) == GIT_DIFF_FIND_BY_CONFIG) (given->flags & GIT_DIFF_FIND_ALL) == GIT_DIFF_FIND_BY_CONFIG)
{ {
char *rule = if (diff->repo) {
git_config__get_string_force(cfg, "diff.renames", "true"); char *rule =
int boolval; git_config__get_string_force(cfg, "diff.renames", "true");
int boolval;
if (!git__parse_bool(&boolval, rule) && !boolval) if (!git__parse_bool(&boolval, rule) && !boolval)
/* don't set FIND_RENAMES if bool value is false */; /* don't set FIND_RENAMES if bool value is false */;
else if (!strcasecmp(rule, "copies") || !strcasecmp(rule, "copy")) else if (!strcasecmp(rule, "copies") || !strcasecmp(rule, "copy"))
opts->flags |= GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES; opts->flags |= GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
else else
opts->flags |= GIT_DIFF_FIND_RENAMES;
git__free(rule);
} else {
/* set default flag */
opts->flags |= GIT_DIFF_FIND_RENAMES; opts->flags |= GIT_DIFF_FIND_RENAMES;
}
git__free(rule);
} }
/* some flags imply others */ /* some flags imply others */