From e738bb56422c4557e731b96684f0d6832e49aca3 Mon Sep 17 00:00:00 2001 From: itojun Date: Mon, 24 Apr 2000 02:53:05 +0000 Subject: [PATCH] avoid NULL pointer access when rp= (no ai_canonname). From: hiro@takechi.org XXX checkremote() should be improved. gethostname -> getaddrinfo is not the right thing to do, we cannot assume DNS FQDNs is configured as hostname. if the goal here is to check if it is really remote or not, getifaddrs() is the way to go. --- usr.sbin/lpr/common_source/common.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c index 80e0a44b0aa6..9369aabacd96 100644 --- a/usr.sbin/lpr/common_source/common.c +++ b/usr.sbin/lpr/common_source/common.c @@ -1,4 +1,4 @@ -/* $NetBSD: common.c,v 1.18 2000/02/18 03:53:16 itojun Exp $ */ +/* $NetBSD: common.c,v 1.19 2000/04/24 02:53:05 itojun Exp $ */ /* * Copyright (c) 1983, 1993 @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: common.c,v 1.18 2000/02/18 03:53:16 itojun Exp $"); +__RCSID("$NetBSD: common.c,v 1.19 2000/04/24 02:53:05 itojun Exp $"); #endif #endif /* not lint */ @@ -321,10 +321,12 @@ checkremote() hints.ai_socktype = SOCK_STREAM; res = NULL; error = getaddrinfo(hname, NULL, &hints, &res); - if (error) { + if (error || !res->ai_canonname) { (void)snprintf(errbuf, sizeof(errbuf), "unable to get official name for local machine %s: " "%s", hname, gai_strerror(error)); + if (res) + freeaddrinfo(res); return errbuf; } else { (void)strncpy(hname, res->ai_canonname, @@ -340,10 +342,12 @@ checkremote() hints.ai_socktype = SOCK_STREAM; res = NULL; error = getaddrinfo(RM, NULL, &hints, &res); - if (error) { + if (error || !res->ai_canonname) { (void)snprintf(errbuf, sizeof(errbuf), "unable to get official name for local machine %s: " "%s", RM, gai_strerror(error)); + if (res) + freeaddrinfo(res); return errbuf; }