diff options
Diffstat (limited to 'usr.sbin/lpd')
-rw-r--r-- | usr.sbin/lpd/engine_lpr.c | 12 | ||||
-rw-r--r-- | usr.sbin/lpd/frontend_lpr.c | 7 | ||||
-rw-r--r-- | usr.sbin/lpd/proc.c | 19 | ||||
-rw-r--r-- | usr.sbin/lpd/resolver.c | 29 |
4 files changed, 37 insertions, 30 deletions
diff --git a/usr.sbin/lpd/engine_lpr.c b/usr.sbin/lpd/engine_lpr.c index 5de965f3e6a..2d019d89c3b 100644 --- a/usr.sbin/lpd/engine_lpr.c +++ b/usr.sbin/lpd/engine_lpr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine_lpr.c,v 1.1 2018/04/27 16:14:35 eric Exp $ */ +/* $OpenBSD: engine_lpr.c,v 1.2 2019/04/04 19:25:45 eric Exp $ */ /* * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> @@ -302,7 +302,7 @@ lpr_allowedhost_res(uint32_t connid, const char *hostname, const char *reject) { m_create(p_frontend, IMSG_LPR_ALLOWEDHOST, connid, 0, -1); m_add_string(p_frontend, hostname); - m_add_string(p_frontend, reject ? reject : ""); + m_add_string(p_frontend, reject); m_close(p_frontend); } @@ -426,8 +426,8 @@ static void lpr_displayq_res(uint32_t connid, int fd, const char *host, const char *cmd) { m_create(p_frontend, IMSG_LPR_DISPLAYQ, connid, 0, fd); - m_add_string(p_frontend, host ? host : ""); - m_add_string(p_frontend, cmd ? cmd : ""); + m_add_string(p_frontend, host); + m_add_string(p_frontend, cmd); m_close(p_frontend); } @@ -479,8 +479,8 @@ static void lpr_rmjob_res(uint32_t connid, int fd, const char *host, const char *cmd) { m_create(p_frontend, IMSG_LPR_RMJOB, connid, 0, fd); - m_add_string(p_frontend, host ? host : ""); - m_add_string(p_frontend, cmd ? cmd : ""); + m_add_string(p_frontend, host); + m_add_string(p_frontend, cmd); m_close(p_frontend); } diff --git a/usr.sbin/lpd/frontend_lpr.c b/usr.sbin/lpd/frontend_lpr.c index ad9c94f92af..778343e6cae 100644 --- a/usr.sbin/lpd/frontend_lpr.c +++ b/usr.sbin/lpd/frontend_lpr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend_lpr.c,v 1.1 2018/04/27 16:14:35 eric Exp $ */ +/* $OpenBSD: frontend_lpr.c,v 1.2 2019/04/04 19:25:45 eric Exp $ */ /* * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> @@ -159,7 +159,7 @@ lpr_dispatch_engine(struct imsgproc *proc, struct imsg *imsg) m_get_string(proc, &hostname); m_get_string(proc, &reject); m_end(proc); - lpr_on_allowedhost(conn, hostname, reject[0] ? reject : NULL); + lpr_on_allowedhost(conn, hostname, reject); break; case IMSG_LPR_RECVJOB: @@ -182,8 +182,7 @@ lpr_dispatch_engine(struct imsgproc *proc, struct imsg *imsg) m_get_string(proc, &hostname); m_get_string(proc, &cmd); m_end(proc); - lpr_on_request(conn, imsg->fd, hostname[0] ? hostname : NULL, - cmd[0] ? cmd : NULL); + lpr_on_request(conn, imsg->fd, hostname, cmd); break; default: diff --git a/usr.sbin/lpd/proc.c b/usr.sbin/lpd/proc.c index b3aabcb4b59..a7276bddcb3 100644 --- a/usr.sbin/lpd/proc.c +++ b/usr.sbin/lpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.1 2018/04/27 16:14:37 eric Exp $ */ +/* $OpenBSD: proc.c,v 1.2 2019/04/04 19:25:46 eric Exp $ */ /* * Copyright (c) 2017 Eric Faurot <eric@openbsd.org> @@ -416,7 +416,12 @@ m_add_time(struct imsgproc *p, time_t v) void m_add_string(struct imsgproc *p, const char *str) { - m_add(p, str, strlen(str) + 1); + if (str) { + m_add(p, "s", 1); + m_add(p, str, strlen(str) + 1); + } + else + m_add(p, "\0", 1); } void @@ -485,11 +490,19 @@ m_get_time(struct imsgproc *p, time_t *dst) void m_get_string(struct imsgproc *p, const char **dst) { - char *end; + char *end, c; if (p->m_in.pos >= p->m_in.end) fatalx("%s: no data left", __func__); + c = *p->m_in.pos++; + if (c == '\0') { + *dst = NULL; + return; + } + + if (p->m_in.pos >= p->m_in.end) + fatalx("%s: no data left", __func__); end = memchr(p->m_in.pos, 0, p->m_in.end - p->m_in.pos); if (end == NULL) fatalx("%s: unterminated string", __func__); diff --git a/usr.sbin/lpd/resolver.c b/usr.sbin/lpd/resolver.c index adcbb13c3b6..5b73e29b618 100644 --- a/usr.sbin/lpd/resolver.c +++ b/usr.sbin/lpd/resolver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolver.c,v 1.2 2018/09/05 17:32:56 eric Exp $ */ +/* $OpenBSD: resolver.c,v 1.3 2019/04/04 19:25:46 eric Exp $ */ /* * Copyright (c) 2017-2018 Eric Faurot <eric@openbsd.org> @@ -95,7 +95,7 @@ resolver_getaddrinfo(const char *hostname, const char *servname, m_add_int(p_resolver, hints ? hints->ai_socktype : 0); m_add_int(p_resolver, hints ? hints->ai_protocol : 0); m_add_string(p_resolver, hostname); - m_add_string(p_resolver, servname ? servname : ""); + m_add_string(p_resolver, servname); m_close(p_resolver); } @@ -150,8 +150,7 @@ resolver_dispatch_request(struct imsgproc *proc, struct imsg *imsg) m_get_int(proc, &hints.ai_socktype); m_get_int(proc, &hints.ai_protocol); m_get_string(proc, &hostname); - if (!m_is_eom(proc)) - m_get_string(proc, &servname); + m_get_string(proc, &servname); m_end(proc); s = NULL; @@ -207,6 +206,8 @@ resolver_dispatch_request(struct imsgproc *proc, struct imsg *imsg) m_create(proc, IMSG_GETNAMEINFO, reqid, 0, -1); m_add_int(proc, EAI_SYSTEM); m_add_int(proc, save_errno); + m_add_string(proc, NULL); + m_add_string(proc, NULL); m_close(proc); break; @@ -254,7 +255,7 @@ resolver_dispatch_result(struct imsgproc *proc, struct imsg *imsg) memmove(ai->ai_addr, &ss, ss.ss_len); - if (cname[0]) { + if (cname) { ai->ai_canonname = strdup(cname); if (ai->ai_canonname == NULL) { log_warn("%s: strdup", __func__); @@ -281,15 +282,12 @@ resolver_dispatch_result(struct imsgproc *proc, struct imsg *imsg) case IMSG_GETNAMEINFO: m_get_int(proc, &gai_errno); m_get_int(proc, &errno); - if (gai_errno == 0) { - m_get_string(proc, &host); - m_get_string(proc, &serv); - } + m_get_string(proc, &host); + m_get_string(proc, &serv); m_end(proc); SPLAY_REMOVE(reqtree, &reqs, req); - req->cb_ni(req->arg, gai_errno, gai_errno ? NULL : host, - gai_errno ? NULL : serv); + req->cb_ni(req->arg, gai_errno, host, serv); free(req); break; } @@ -319,8 +317,7 @@ resolver_getaddrinfo_cb(struct asr_result *ar, void *arg) m_add_int(s->proc, ai->ai_socktype); m_add_int(s->proc, ai->ai_protocol); m_add_sockaddr(s->proc, ai->ai_addr); - m_add_string(s->proc, ai->ai_canonname ? - ai->ai_canonname : ""); + m_add_string(s->proc, ai->ai_canonname); m_close(s->proc); } @@ -341,10 +338,8 @@ resolver_getnameinfo_cb(struct asr_result *ar, void *arg) m_create(s->proc, IMSG_GETNAMEINFO, s->reqid, 0, -1); m_add_int(s->proc, ar->ar_gai_errno); m_add_int(s->proc, ar->ar_errno); - if (ar->ar_gai_errno == 0) { - m_add_string(s->proc, s->host); - m_add_string(s->proc, s->serv); - } + m_add_string(s->proc, ar->ar_gai_errno ? NULL : s->host); + m_add_string(s->proc, ar->ar_gai_errno ? NULL : s->serv); m_close(s->proc); free(s->host); |