mirror of
https://github.com/yarrick/iodine.git
synced 2025-01-12 19:09:30 +00:00
Simplify NULL checks.
This commit is contained in:
parent
ca3dde98e9
commit
9634d0271f
|
@ -255,7 +255,7 @@ do_pidfile(char *pidfile)
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
if ((file = fopen(pidfile, "w")) == NULL) {
|
if ((file = fopen(pidfile, "w"))) {
|
||||||
syslog(LOG_ERR, "Cannot write pidfile to %s, exiting", pidfile);
|
syslog(LOG_ERR, "Cannot write pidfile to %s, exiting", pidfile);
|
||||||
err(1, "do_pidfile: Can not write pidfile to %s", pidfile);
|
err(1, "do_pidfile: Can not write pidfile to %s", pidfile);
|
||||||
} else {
|
} else {
|
||||||
|
|
10
src/dns.c
10
src/dns.c
|
@ -431,7 +431,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
|
|
||||||
rlen = 0;
|
rlen = 0;
|
||||||
|
|
||||||
if (q != NULL)
|
if (q)
|
||||||
q->rcode = header->rcode;
|
q->rcode = header->rcode;
|
||||||
|
|
||||||
switch (qr) {
|
switch (qr) {
|
||||||
|
@ -441,7 +441,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (q != NULL)
|
if (q)
|
||||||
q->id = id;
|
q->id = id;
|
||||||
|
|
||||||
/* Read name even if no answer, to give better error message */
|
/* Read name even if no answer, to give better error message */
|
||||||
|
@ -451,7 +451,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
readshort(packet, &data, &class);
|
readshort(packet, &data, &class);
|
||||||
|
|
||||||
/* if CHECKLEN okay, then we're sure to have a proper name */
|
/* if CHECKLEN okay, then we're sure to have a proper name */
|
||||||
if (q != NULL) {
|
if (q) {
|
||||||
/* We only need the first char to check it */
|
/* We only need the first char to check it */
|
||||||
q->name[0] = name[0];
|
q->name[0] = name[0];
|
||||||
q->name[1] = '\0';
|
q->name[1] = '\0';
|
||||||
|
@ -577,7 +577,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Here type is the answer type (note A->CNAME) */
|
/* Here type is the answer type (note A->CNAME) */
|
||||||
if (q != NULL)
|
if (q)
|
||||||
q->type = type;
|
q->type = type;
|
||||||
break;
|
break;
|
||||||
case QR_QUERY:
|
case QR_QUERY:
|
||||||
|
@ -593,7 +593,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
readshort(packet, &data, &type);
|
readshort(packet, &data, &type);
|
||||||
readshort(packet, &data, &class);
|
readshort(packet, &data, &class);
|
||||||
|
|
||||||
if (q == NULL) {
|
if (!q) {
|
||||||
rv = 0;
|
rv = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
16
src/iodine.c
16
src/iodine.c
|
@ -173,7 +173,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
#if !defined(BSD) && !defined(__GLIBC__)
|
#if !defined(BSD) && !defined(__GLIBC__)
|
||||||
__progname = strrchr(argv[0], '/');
|
__progname = strrchr(argv[0], '/');
|
||||||
if (__progname == NULL)
|
if (!__progname)
|
||||||
__progname = argv[0];
|
__progname = argv[0];
|
||||||
else
|
else
|
||||||
__progname++;
|
__progname++;
|
||||||
|
@ -320,9 +320,9 @@ main(int argc, char **argv)
|
||||||
client_set_topdomain(topdomain);
|
client_set_topdomain(topdomain);
|
||||||
client_set_hostname_maxlen(hostname_maxlen);
|
client_set_hostname_maxlen(hostname_maxlen);
|
||||||
|
|
||||||
if (username != NULL) {
|
if (username) {
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
if ((pw = getpwnam(username)) == NULL) {
|
if (!(pw = getpwnam(username))) {
|
||||||
warnx("User %s does not exist!\n", username);
|
warnx("User %s does not exist!\n", username);
|
||||||
usage();
|
usage();
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
|
@ -331,7 +331,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(password) == 0) {
|
if (strlen(password) == 0) {
|
||||||
if (NULL != getenv(PASSWORD_ENV_VAR))
|
if (getenv(PASSWORD_ENV_VAR))
|
||||||
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
|
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
|
||||||
else
|
else
|
||||||
read_password(password, sizeof(password));
|
read_password(password, sizeof(password));
|
||||||
|
@ -372,13 +372,13 @@ main(int argc, char **argv)
|
||||||
if (foreground == 0)
|
if (foreground == 0)
|
||||||
do_detach();
|
do_detach();
|
||||||
|
|
||||||
if (pidfile != NULL)
|
if (pidfile)
|
||||||
do_pidfile(pidfile);
|
do_pidfile(pidfile);
|
||||||
|
|
||||||
if (newroot != NULL)
|
if (newroot)
|
||||||
do_chroot(newroot);
|
do_chroot(newroot);
|
||||||
|
|
||||||
if (username != NULL) {
|
if (username) {
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
gid_t gids[1];
|
gid_t gids[1];
|
||||||
gids[0] = pw->pw_gid;
|
gids[0] = pw->pw_gid;
|
||||||
|
@ -390,7 +390,7 @@ main(int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context != NULL)
|
if (context)
|
||||||
do_setcon(context);
|
do_setcon(context);
|
||||||
|
|
||||||
client_tunnel(tun_fd, dns_fd);
|
client_tunnel(tun_fd, dns_fd);
|
||||||
|
|
|
@ -415,7 +415,7 @@ save_to_qmem_pingordata(int userid, struct query *q)
|
||||||
size_t cmcsize = sizeof(cmc);
|
size_t cmcsize = sizeof(cmc);
|
||||||
char *cp = strchr(q->name, '.');
|
char *cp = strchr(q->name, '.');
|
||||||
|
|
||||||
if (cp == NULL)
|
if (!cp)
|
||||||
return; /* illegal hostname; shouldn't happen */
|
return; /* illegal hostname; shouldn't happen */
|
||||||
|
|
||||||
/* We already unpacked in handle_null_request(), but that's
|
/* We already unpacked in handle_null_request(), but that's
|
||||||
|
@ -1993,9 +1993,7 @@ read_dns(int fd, int tun_fd, struct query *q) /* FIXME: tun_fd is because of raw
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
|
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||||
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
|
||||||
|
|
||||||
if (cmsg->cmsg_level == IPPROTO_IP &&
|
if (cmsg->cmsg_level == IPPROTO_IP &&
|
||||||
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
|
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
|
||||||
|
|
||||||
|
@ -2298,7 +2296,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
#if !defined(BSD) && !defined(__GLIBC__)
|
#if !defined(BSD) && !defined(__GLIBC__)
|
||||||
__progname = strrchr(argv[0], '/');
|
__progname = strrchr(argv[0], '/');
|
||||||
if (__progname == NULL)
|
if (!__progname)
|
||||||
__progname = argv[0];
|
__progname = argv[0];
|
||||||
else
|
else
|
||||||
__progname++;
|
__progname++;
|
||||||
|
@ -2412,9 +2410,9 @@ main(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username != NULL) {
|
if (username) {
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
if ((pw = getpwnam(username)) == NULL) {
|
if (!(pw = getpwnam(username))) {
|
||||||
warnx("User %s does not exist!", username);
|
warnx("User %s does not exist!", username);
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
@ -2543,7 +2541,7 @@ main(int argc, char **argv)
|
||||||
if (foreground == 0)
|
if (foreground == 0)
|
||||||
do_detach();
|
do_detach();
|
||||||
|
|
||||||
if (pidfile != NULL)
|
if (pidfile)
|
||||||
do_pidfile(pidfile);
|
do_pidfile(pidfile);
|
||||||
|
|
||||||
#ifdef FREEBSD
|
#ifdef FREEBSD
|
||||||
|
@ -2553,11 +2551,11 @@ main(int argc, char **argv)
|
||||||
openlog( __progname, LOG_NDELAY, LOG_DAEMON );
|
openlog( __progname, LOG_NDELAY, LOG_DAEMON );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (newroot != NULL)
|
if (newroot)
|
||||||
do_chroot(newroot);
|
do_chroot(newroot);
|
||||||
|
|
||||||
signal(SIGINT, sigint);
|
signal(SIGINT, sigint);
|
||||||
if (username != NULL) {
|
if (username) {
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
gid_t gids[1];
|
gid_t gids[1];
|
||||||
gids[0] = pw->pw_gid;
|
gids[0] = pw->pw_gid;
|
||||||
|
@ -2568,7 +2566,7 @@ main(int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context != NULL)
|
if (context)
|
||||||
do_setcon(context);
|
do_setcon(context);
|
||||||
|
|
||||||
syslog(LOG_INFO, "started, listening on port %d", port);
|
syslog(LOG_INFO, "started, listening on port %d", port);
|
||||||
|
|
|
@ -89,7 +89,7 @@ open_tun(const char *tun_device)
|
||||||
|
|
||||||
ifreq.ifr_flags = IFF_TUN;
|
ifreq.ifr_flags = IFF_TUN;
|
||||||
|
|
||||||
if (tun_device != NULL) {
|
if (tun_device) {
|
||||||
strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ);
|
strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ);
|
||||||
ifreq.ifr_name[IFNAMSIZ-1] = '\0';
|
ifreq.ifr_name[IFNAMSIZ-1] = '\0';
|
||||||
strncpy(if_name, tun_device, sizeof(if_name));
|
strncpy(if_name, tun_device, sizeof(if_name));
|
||||||
|
@ -135,7 +135,7 @@ open_tun(const char *tun_device)
|
||||||
int tun_fd;
|
int tun_fd;
|
||||||
char tun_name[50];
|
char tun_name[50];
|
||||||
|
|
||||||
if (tun_device != NULL) {
|
if (tun_device) {
|
||||||
snprintf(tun_name, sizeof(tun_name), "/dev/%s", tun_device);
|
snprintf(tun_name, sizeof(tun_name), "/dev/%s", tun_device);
|
||||||
strncpy(if_name, tun_device, sizeof(if_name));
|
strncpy(if_name, tun_device, sizeof(if_name));
|
||||||
if_name[sizeof(if_name)-1] = '\0';
|
if_name[sizeof(if_name)-1] = '\0';
|
||||||
|
|
|
@ -27,9 +27,9 @@ get_resolvconf_addr(void)
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
fp = popen("getprop net.dns1", "r");
|
fp = popen("getprop net.dns1", "r");
|
||||||
if (fp == NULL)
|
if (!fp)
|
||||||
err(1, "getprop net.dns1 failed");
|
err(1, "getprop net.dns1 failed");
|
||||||
if (fgets(buf, sizeof(buf), fp) == NULL)
|
if (!fgets(buf, sizeof(buf), fp))
|
||||||
err(1, "read getprop net.dns1 failed");
|
err(1, "read getprop net.dns1 failed");
|
||||||
if (sscanf(buf, "%15s", addr) == 1)
|
if (sscanf(buf, "%15s", addr) == 1)
|
||||||
rv = addr;
|
rv = addr;
|
||||||
|
@ -38,7 +38,7 @@ get_resolvconf_addr(void)
|
||||||
|
|
||||||
rv = NULL;
|
rv = NULL;
|
||||||
|
|
||||||
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
|
if (!(fp = fopen("/etc/resolv.conf", "r")))
|
||||||
err(1, "/etc/resolv.conf");
|
err(1, "/etc/resolv.conf");
|
||||||
|
|
||||||
while (feof(fp) == 0) {
|
while (feof(fp) == 0) {
|
||||||
|
|
Loading…
Reference in a new issue