Skip to content

Commit 83e9c5e

Browse files
committed
Track the number of affected pkgs as well and display to the user.
Thanks to @wca for the review. This fixes freebsd#1463.
1 parent 8082f17 commit 83e9c5e

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

libpkg/pkg.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ int pkg_audit_process(struct pkg_audit *audit);
16941694
* @return true and `*result` is set if a package is vulnerable
16951695
*/
16961696
bool pkg_audit_is_vulnerable(struct pkg_audit *audit, struct pkg *pkg,
1697-
bool quiet, UT_string **result);
1697+
bool quiet, UT_string **result, int *affected);
16981698
#endif
16991699

17001700
void pkg_audit_free (struct pkg_audit *audit);

libpkg/pkg_audit.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ pkg_audit_print_entry(struct pkg_audit_entry *e, UT_string *sb,
766766

767767
bool
768768
pkg_audit_is_vulnerable(struct pkg_audit *audit, struct pkg *pkg,
769-
bool quiet, UT_string **result)
769+
bool quiet, UT_string **result, int *affected)
770770
{
771771
struct pkg_audit_entry *e;
772772
struct pkg_audit_versions_range *vers;
@@ -807,6 +807,9 @@ pkg_audit_is_vulnerable(struct pkg_audit *audit, struct pkg *pkg,
807807
*/
808808
res = true;
809809
pkg_audit_print_entry(e, sb, pkg->name, NULL, quiet);
810+
if (affected != NULL) {
811+
++*affected;
812+
}
810813
}
811814
else {
812815
LL_FOREACH(e->versions, vers) {
@@ -816,6 +819,9 @@ pkg_audit_is_vulnerable(struct pkg_audit *audit, struct pkg *pkg,
816819
if (res1 && res2) {
817820
res = true;
818821
pkg_audit_print_entry(e, sb, pkg->name, pkg->version, quiet);
822+
if (affected != NULL) {
823+
++*affected;
824+
}
819825
break;
820826
}
821827
}

src/audit.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ exec_audit(int argc, char **argv)
120120
char *name;
121121
char *version;
122122
char *audit_file = NULL;
123-
unsigned int vuln = 0;
123+
unsigned int affected = 0, vuln = 0;
124124
bool fetch = false, recursive = false;
125125
int ch, i;
126126
int ret = EX_OK;
@@ -276,7 +276,7 @@ exec_audit(int argc, char **argv)
276276

277277
if (pkg_audit_process(audit) == EPKG_OK) {
278278
kh_foreach_value(check, pkg, {
279-
if (pkg_audit_is_vulnerable(audit, pkg, quiet, &sb)) {
279+
if (pkg_audit_is_vulnerable(audit, pkg, quiet, &sb, &affected)) {
280280
vuln ++;
281281
printf("%s", utstring_body(sb));
282282

@@ -302,7 +302,8 @@ exec_audit(int argc, char **argv)
302302
ret = EX_OK;
303303

304304
if (!quiet)
305-
printf("%u problem(s) in the installed packages found.\n", vuln);
305+
printf("%u problem(s) in %u installed package(s) found.\n",
306+
affected, vuln);
306307
}
307308
else {
308309
warnx("cannot process vulnxml");

src/upgrade.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ check_vulnerable(struct pkg_audit *audit, struct pkgdb *db, int sock)
149149

150150
if (pkg_audit_process(audit) == EPKG_OK) {
151151
kh_foreach_value(check, pkg, {
152-
if (pkg_audit_is_vulnerable(audit, pkg, true, &sb)) {
152+
if (pkg_audit_is_vulnerable(audit, pkg, true, &sb, NULL)) {
153153
pkg_get(pkg, PKG_UNIQUEID, &uid);
154154
fprintf(out, "%s\n", uid);
155155
fflush(out);

0 commit comments

Comments
 (0)