From a626c50944c8aa4f3ef92c370422068ba3074680 Mon Sep 17 00:00:00 2001 From: tron Date: Mon, 5 Aug 2002 08:04:03 +0000 Subject: [PATCH] Avoid segmentation fault if "finger @somehost" is used. --- usr.bin/finger/Makefile | 5 ++++- usr.bin/finger/finger.c | 9 +++++---- usr.bin/finger/lprint.c | 7 +++++-- usr.bin/finger/sprint.c | 7 +++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/usr.bin/finger/Makefile b/usr.bin/finger/Makefile index bf4472ca6a8d..3ac61b6abd38 100644 --- a/usr.bin/finger/Makefile +++ b/usr.bin/finger/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.6 2002/08/02 00:10:40 christos Exp $ +# $NetBSD: Makefile,v 1.7 2002/08/05 08:04:03 tron Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= finger @@ -7,4 +7,7 @@ SRCS= finger.c lprint.c net.c sprint.c util.c utmpentry.c .PATH.c: ${.CURDIR}/../../usr.bin/who CPPFLAGS+=-I${.CURDIR}/../../usr.bin/who -DSUPPORT_UTMPX -DSUPPORT_UTMP -DINET6 +CFLAGS+= -g +LDFLAGS+= -g + .include diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c index e33182ab757b..238da59313f8 100644 --- a/usr.bin/finger/finger.c +++ b/usr.bin/finger/finger.c @@ -1,4 +1,4 @@ -/* $NetBSD: finger.c,v 1.16 2002/08/02 00:10:40 christos Exp $ */ +/* $NetBSD: finger.c,v 1.17 2002/08/05 08:04:03 tron Exp $ */ /* * Copyright (c) 1989, 1993 @@ -56,7 +56,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ #if 0 static char sccsid[] = "@(#)finger.c 8.5 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: finger.c,v 1.16 2002/08/02 00:10:40 christos Exp $"); +__RCSID("$NetBSD: finger.c,v 1.17 2002/08/05 08:04:03 tron Exp $"); #endif #endif /* not lint */ @@ -146,7 +146,7 @@ main(argc, argv) (void)time(&now); setpassent(1); entries = getutentries(NULL, &ehead); - if (!*argv) { + if (argc == 0) { /* * Assign explicit "small" format if no names given and -l * not selected. Force the -s BEFORE we get names so proper @@ -277,7 +277,7 @@ net: continue; enter_where(ep, pn); } - if (db) + if (db != NULL) for (sflag = R_FIRST;; sflag = R_NEXT) { PERSON *tmp; @@ -290,3 +290,4 @@ net: enter_lastlog(tmp); } } + diff --git a/usr.bin/finger/lprint.c b/usr.bin/finger/lprint.c index 9c73109cd98f..b951e8954933 100644 --- a/usr.bin/finger/lprint.c +++ b/usr.bin/finger/lprint.c @@ -1,4 +1,4 @@ -/* $NetBSD: lprint.c,v 1.13 2002/08/02 00:10:40 christos Exp $ */ +/* $NetBSD: lprint.c,v 1.14 2002/08/05 08:04:03 tron Exp $ */ /* * Copyright (c) 1989, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)lprint.c 8.3 (Berkeley) 4/28/95"; #else -__RCSID( "$NetBSD: lprint.c,v 1.13 2002/08/02 00:10:40 christos Exp $"); +__RCSID( "$NetBSD: lprint.c,v 1.14 2002/08/05 08:04:03 tron Exp $"); #endif #endif /* not lint */ @@ -93,6 +93,9 @@ lflag_print() PERSON *tmp; DBT data, key; + if (db == NULL) + return; + for (sflag = R_FIRST;; sflag = R_NEXT) { r = (*db->seq)(db, &key, &data, sflag); if (r == -1) diff --git a/usr.bin/finger/sprint.c b/usr.bin/finger/sprint.c index 1f2d136fa0ba..99cc6faba772 100644 --- a/usr.bin/finger/sprint.c +++ b/usr.bin/finger/sprint.c @@ -1,4 +1,4 @@ -/* $NetBSD: sprint.c,v 1.11 2002/08/02 00:10:40 christos Exp $ */ +/* $NetBSD: sprint.c,v 1.12 2002/08/05 08:04:03 tron Exp $ */ /* * Copyright (c) 1989, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: sprint.c,v 1.11 2002/08/02 00:10:40 christos Exp $"); +__RCSID("$NetBSD: sprint.c,v 1.12 2002/08/05 08:04:03 tron Exp $"); #endif #endif /* not lint */ @@ -76,6 +76,9 @@ sflag_print() PERSON *tmp; DBT data, key; + if (db == NULL) + return; + /* * short format -- * login name