From 90179254d28a946487389bdf6cd68c82f95cba48 Mon Sep 17 00:00:00 2001 From: wiz Date: Tue, 4 Apr 2006 06:36:12 +0000 Subject: Pull over v1.59-v1.61 from src/usr.sbin: revision 1.61 date: 2006/03/17 17:46:44; author: hubertf; state: Exp; lines: +4 -3 Put check if "best" is empty back into the right place, messed up in previous commit. Noted by yamt@ ---------------------------- revision 1.60 date: 2006/03/17 02:20:46; author: hubertf; state: Exp; lines: +10 -4 findbestmatchingname_fn(): catch possible problems if best (vp) contains some strange name (shouldn't happen, but ...) Coverity CID 869 ---------------------------- revision 1.59 date: 2006/03/17 02:10:55; author: hubertf; state: Exp; lines: +8 -7 findbestmatchingname_fn(): only do something sensible if the pointer handed in is actually usable (not NULL) Fixes Coverity ID 870 --- pkgtools/pkg_install/files/lib/str.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'pkgtools/pkg_install') diff --git a/pkgtools/pkg_install/files/lib/str.c b/pkgtools/pkg_install/files/lib/str.c index b636c5da0b5..2ad1c85cda1 100644 --- a/pkgtools/pkg_install/files/lib/str.c +++ b/pkgtools/pkg_install/files/lib/str.c @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.16 2006/01/08 12:25:06 wiz Exp $ */ +/* $NetBSD: str.c,v 1.17 2006/04/04 06:36:12 wiz Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -11,7 +11,7 @@ #if 0 static const char *rcsid = "Id: str.c,v 1.5 1997/10/08 07:48:21 charnier Exp"; #else -__RCSID("$NetBSD: str.c,v 1.16 2006/01/08 12:25:06 wiz Exp $"); +__RCSID("$NetBSD: str.c,v 1.17 2006/04/04 06:36:12 wiz Exp $"); #endif #endif @@ -307,9 +307,15 @@ findbestmatchingname_fn(const char *found, void *vp) if (best_version) { /* skip '-' if any version found */ best_version++; + strip_txz(best_no_sfx, NULL, best_version); + best_version = best_no_sfx; + } else { + /* how did this end up in 'best'? + * Shouldn't happen... */ + fprintf(stderr, + "'%s' has no usable package(version)\n", + best); } - strip_txz(best_no_sfx, NULL, best_version); - best_version = best_no_sfx; } if (found_version == NULL) { @@ -318,11 +324,13 @@ findbestmatchingname_fn(const char *found, void *vp) } else { /* if best_version==NULL only if best==NULL * (or best[0]='\0') */ - if (best == NULL || best[0] == '\0' || - dewey_cmp(found_version, DEWEY_GT, best_version)) { - /* found pkg(version) is bigger than current "best" - * version - remember! */ - strcpy(best, found); + if (best != NULL) { + if (best[0] == '\0' + || dewey_cmp(found_version, DEWEY_GT, best_version)) { + /* found pkg(version) is bigger than current "best" + * version - remember! */ + strcpy(best, found); + } } } -- cgit v1.2.3