Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32f0798

Browse files
committed
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.
1 parent 3d1abc5 commit 32f0798

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/diff_tform.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,23 @@ static int normalize_find_opts(
261261
if (!given ||
262262
(given->flags & GIT_DIFF_FIND_ALL) == GIT_DIFF_FIND_BY_CONFIG)
263263
{
264-
char *rule =
265-
git_config__get_string_force(cfg, "diff.renames", "true");
266-
int boolval;
267-
268-
if (!git__parse_bool(&boolval, rule) && !boolval)
269-
/* don't set FIND_RENAMES if bool value is false */;
270-
else if (!strcasecmp(rule, "copies") || !strcasecmp(rule, "copy"))
271-
opts->flags |= GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
272-
else
273-
opts->flags |= GIT_DIFF_FIND_RENAMES;
264+
if (diff->repo) {
265+
char *rule =
266+
git_config__get_string_force(cfg, "diff.renames", "true");
267+
int boolval;
268+
269+
if (!git__parse_bool(&boolval, rule) && !boolval)
270+
/* don't set FIND_RENAMES if bool value is false */;
271+
else if (!strcasecmp(rule, "copies") || !strcasecmp(rule, "copy"))
272+
opts->flags |= GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
273+
else
274+
opts->flags |= GIT_DIFF_FIND_RENAMES;
274275

275-
git__free(rule);
276+
git__free(rule);
277+
} else {
278+
/* set default flag */
279+
opts->flags |= GIT_DIFF_FIND_RENAMES;
280+
}
276281
}
277282

278283
/* some flags imply others */

0 commit comments

Comments
 (0)