Skip to content

Commit

Permalink
Do not crash when querying provides that do not exist
Browse files Browse the repository at this point in the history
hy_reldep_create() returns NULL if nothing provides the name, so only add it to
the reldeplist if it's going to exist.
  • Loading branch information
hughsie committed Dec 16, 2013
1 parent 592af7d commit 3b31eea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/query.c
Expand Up @@ -1008,7 +1008,8 @@ hy_query_filter_provides_in(HyQuery q, char **reldep_strs)
return HY_E_QUERY;
}
reldep = hy_reldep_create(q->sack, name, cmp_type, evr);
hy_reldeplist_add(reldeplist, reldep);
if (reldep)
hy_reldeplist_add(reldeplist, reldep);
hy_reldep_free(reldep);
solv_free(name);
solv_free(evr);
Expand Down
14 changes: 14 additions & 0 deletions tests/test_query.c
Expand Up @@ -370,6 +370,19 @@ START_TEST(test_query_provides_in)
}
END_TEST

START_TEST(test_query_provides_in_not_found)
{
HyPackageList plist;
char* provides[] = { "thisisnotgoingtoexist", NULL };
HyQuery q = hy_query_create(test_globals.sack);
hy_query_filter_provides_in(q, provides);
plist = hy_query_run(q);
fail_unless(hy_packagelist_count(plist) == 0);
hy_packagelist_free(plist);
hy_query_free(q);
}
END_TEST

START_TEST(test_query_fileprovides)
{
HyQuery q = hy_query_create(test_globals.sack);
Expand Down Expand Up @@ -761,6 +774,7 @@ query_suite(void)
tcase_add_test(tc, test_upgrades);
tcase_add_test(tc, test_filter_latest);
tcase_add_test(tc, test_query_provides_in);
tcase_add_test(tc, test_query_provides_in_not_found);
suite_add_tcase(s, tc);

tc = tcase_create("Main");
Expand Down

0 comments on commit 3b31eea

Please sign in to comment.