diff options
author | robert <robert@FreeBSD.org> | 2003-04-04 14:40:49 +0000 |
---|---|---|
committer | robert <robert@FreeBSD.org> | 2003-04-04 14:40:49 +0000 |
commit | a882342fd83b0efeef18cc67e1486e2f725d88e4 (patch) | |
tree | 4fd5017871a387d8937d2ddc0ec85b11d1e05d73 /usr.sbin/pkg_install/version | |
parent | 9e59a398a59c6010a152f04feb3b33f011f9aeae (diff) | |
download | FreeBSD-src-a882342fd83b0efeef18cc67e1486e2f725d88e4.zip FreeBSD-src-a882342fd83b0efeef18cc67e1486e2f725d88e4.tar.gz |
- 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
Diffstat (limited to 'usr.sbin/pkg_install/version')
-rw-r--r-- | usr.sbin/pkg_install/version/perform.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/usr.sbin/pkg_install/version/perform.c b/usr.sbin/pkg_install/version/perform.c index db2fb19..6c345b9 100644 --- a/usr.sbin/pkg_install/version/perform.c +++ b/usr.sbin/pkg_install/version/perform.c @@ -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); |