- Print out an error message instead of dereferencing a NULL pointer
if matchinstalled() found no packages, which happens to be the case after fresh installations. - Instead of using strstr(3) to match the package name, depend on matchinstalled()'s MATCH_REGEX package matching. PR: bin/50384 MFC after: 2 weeks
This commit is contained in:
parent
e21115ab06
commit
b61ee45f0e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=113079
@ -44,9 +44,10 @@ static void show_version(const char *, const char *, const char *);
|
||||
int
|
||||
pkg_perform(char **indexarg)
|
||||
{
|
||||
char tmp[PATH_MAX], **pkgs;
|
||||
char tmp[PATH_MAX], **pkgs, *pat[2], **patterns;
|
||||
struct index_entry *ie;
|
||||
int i, err_cnt = 0;
|
||||
int MatchType;
|
||||
|
||||
/*
|
||||
* Try to find and open the INDEX. We only check IndexFile != NULL
|
||||
@ -62,16 +63,37 @@ pkg_perform(char **indexarg)
|
||||
else
|
||||
IndexFile = fopen(tmp, "r");
|
||||
|
||||
/* Get a list of all the installed packages */
|
||||
pkgs = matchinstalled(MATCH_ALL, NULL, &err_cnt);
|
||||
/* Get either a list of matching or all packages */
|
||||
if (MatchName != NULL) {
|
||||
pat[0] = MatchName;
|
||||
pat[1] = NULL;
|
||||
MatchType = MATCH_REGEX;
|
||||
patterns = pat;
|
||||
}
|
||||
else {
|
||||
MatchType = MATCH_ALL;
|
||||
patterns = NULL;
|
||||
}
|
||||
pkgs = matchinstalled(MatchType, patterns, &err_cnt);
|
||||
|
||||
if (err_cnt != 0)
|
||||
errx(2, "Unable to find package database directory!");
|
||||
i = -1;
|
||||
while (pkgs[++i] != NULL) {
|
||||
if (MatchName == NULL || strstr(pkgs[i], MatchName))
|
||||
err_cnt += pkg_do(pkgs[i]);
|
||||
if (pkgs == NULL) {
|
||||
switch (MatchType) {
|
||||
case MATCH_ALL:
|
||||
warnx("no packages installed");
|
||||
return (0);
|
||||
case MATCH_REGEX:
|
||||
warnx("no packages match pattern");
|
||||
return (1);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; pkgs[i] != NULL; i++)
|
||||
err_cnt += pkg_do(pkgs[i]);
|
||||
|
||||
/* If we opened the INDEX in pkg_do(), clean up. */
|
||||
while (!SLIST_EMPTY(&Index)) {
|
||||
ie = SLIST_FIRST(&Index);
|
||||
|
Loading…
Reference in New Issue
Block a user