diff --git a/src/common.c b/src/common.c index befb533..19b4461 100644 --- a/src/common.c +++ b/src/common.c @@ -282,7 +282,9 @@ do_detach() { #ifndef WINDOWS32 fprintf(stderr, "Detaching from terminal...\n"); - daemon(0, 0); + if (daemon(0, 0) != 0) { + err(1, "Failed to detach from terminal. Try running in foreground."); + } umask(0); alarm(0); #else @@ -310,7 +312,8 @@ read_password(char *buf, size_t len) fprintf(stderr, "Enter password: "); fflush(stderr); #ifndef WINDOWS32 - fscanf(stdin, "%79[^\n]", pwd); + if (!fscanf(stdin, "%79[^\n]", pwd)) + err(1, "EOF while reading password!"); #else for (i = 0; i < sizeof(pwd); i++) { pwd[i] = getch(); diff --git a/src/common.h b/src/common.h index d357454..d942027 100644 --- a/src/common.h +++ b/src/common.h @@ -79,7 +79,7 @@ extern const unsigned char raw_header[RAW_HDR_LEN]; #define DOWNSTREAM_HDR 3 #define DOWNSTREAM_PING_HDR 7 #define UPSTREAM_HDR 6 -#define UPSTREAM_PING 6 +#define UPSTREAM_PING 11 /* handy debug printing macro */ #define DEBUG(level, ...) \ diff --git a/src/dns.c b/src/dns.c index b933a2d..e6a807e 100644 --- a/src/dns.c +++ b/src/dns.c @@ -408,7 +408,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz unsigned short type; char *data; unsigned short rlen; - int id; + uint16_t id; int rv; rv = 0; @@ -428,7 +428,6 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz ancount = ntohs(header->ancount); id = ntohs(header->id); - id = id & 0xFFFF; /* Kill any sign extension */ rlen = 0; diff --git a/src/util.c b/src/util.c index 5cbad72..5780031 100644 --- a/src/util.c +++ b/src/util.c @@ -43,7 +43,10 @@ get_resolvconf_addr() err(1, "/etc/resolv.conf"); while (feof(fp) == 0) { - fgets(buf, sizeof(buf), fp); + if (!fgets(buf, sizeof(buf), fp)) { + /* resolv.conf is empty (we got to EOF without reading anything yet */ + err(1, "/etc/resolv.conf is empty! Please specify a nameserver."); + } if (sscanf(buf, "nameserver %15s", addr) == 1) { rv = addr;