summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2013-02-01 15:24:56 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2013-02-01 15:24:56 +0000
commit7d837c72d096900f84f27334082ba75906856698 (patch)
treee65b67e57857b05d1988a26dd8834ff31ce96252
parentb69746fa669461fdf3456121a6f51f73da5845c5 (diff)
Handle a non-existant resolv.conf.tail without issuing an error
message. Handle an empty resolv.conf.tail without exiting. Don't leak an fd if fstat() on resolv.conf.tail fails. Make fstat() failure on successfully opened resolv.conf.tail a fatal error. From Tim van der Molen. Thanks!
-rw-r--r--sbin/dhclient/dhclient.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index c2d0a5209e4..2283f9d2f5f 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.218 2013/02/01 01:33:44 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.219 2013/02/01 15:24:55 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -404,14 +404,21 @@ main(int argc, char *argv[])
apply_ignore_list(ignore_list);
tailfd = open("/etc/resolv.conf.tail", O_RDONLY);
- if (tailfd != -1 && fstat(tailfd, &sb) != -1) {
- config->resolv_tail = calloc(1, sb.st_size + 1);
- if (config->resolv_tail == NULL) {
- error("no memory for resolv.conf.tail contents: %s",
+ if (tailfd == -1) {
+ if (errno != ENOENT)
+ error("Cannot open /etc/resolv.conf.tail: %s",
strerror(errno));
- } else {
- tailn = read(tailfd, config->resolv_tail,
- sb.st_size);
+ } else if (fstat(tailfd, &sb) == -1) {
+ error("Cannot stat /etc/resolv.conf.tail: %s",
+ strerror(errno));
+ } else {
+ if (sb.st_size > 0) {
+ config->resolv_tail = calloc(1, sb.st_size + 1);
+ if (config->resolv_tail == NULL) {
+ error("no memory for resolv.conf.tail "
+ "contents: %s", strerror(errno));
+ }
+ tailn = read(tailfd, config->resolv_tail, sb.st_size);
if (tailn == -1)
error("Couldn't read resolv.conf.tail: %s",
strerror(errno));
@@ -421,8 +428,7 @@ main(int argc, char *argv[])
error("Short read of resolv.conf.tail");
}
close(tailfd);
- } else
- note("/etc/resolv.conf.tail: %s", strerror(errno));
+ }
if (interface_status(ifi->name) == 0) {
interface_link_forceup(ifi->name);