Permalink
Browse files

Do not crash when querying provides that do not exist

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...
1 parent 592af7d commit 3b31eeaa86e89d571dda53b5b10442edcf11cacd @hughsie hughsie committed Dec 16, 2013
Showing with 16 additions and 1 deletion.
  1. +2 −1 src/query.c
  2. +14 −0 tests/test_query.c
View
@@ -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);
View
@@ -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);
@@ -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");

0 comments on commit 3b31eea

Please sign in to comment.