--- sbin/hastd/hast_proto.c.orig +++ sbin/hastd/hast_proto.c @@ -150,12 +150,14 @@ eb = ebuf_alloc(hdr.size); if (eb == NULL) goto fail; - if (ebuf_add_tail(eb, NULL, hdr.size) == -1) - goto fail; - hptr = ebuf_data(eb, NULL); - PJDLOG_ASSERT(hptr != NULL); - if (proto_recv(conn, hptr, hdr.size) == -1) - goto fail; + if (hdr.size > 0) { + if (ebuf_add_tail(eb, NULL, hdr.size) == -1) + goto fail; + hptr = ebuf_data(eb, NULL); + PJDLOG_ASSERT(hptr != NULL); + if (proto_recv(conn, hptr, hdr.size) == -1) + goto fail; + } nv = nv_ntoh(eb); if (nv == NULL) goto fail; --- sbin/hastd/nv.c.orig +++ sbin/hastd/nv.c @@ -500,7 +500,7 @@ return (0); \ PJDLOG_ASSERT((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST);\ PJDLOG_ASSERT(sizeof(value) == nvh->nvh_dsize); \ - bcopy(NVH_DATA(nvh), &value, sizeof(value)); \ + memcpy(&value, NVH_DATA(nvh), sizeof(value)); \ \ return (value); \ } @@ -767,7 +767,7 @@ namesize = strlen(name) + 1; - nvh = malloc(sizeof(*nvh) + roundup2(namesize, 8)); + nvh = calloc(1, sizeof(*nvh) + roundup2(namesize, 8)); if (nvh == NULL) { if (nv->nv_error == 0) nv->nv_error = ENOMEM; @@ -776,7 +776,7 @@ nvh->nvh_type = NV_ORDER_HOST | type; nvh->nvh_namesize = (uint8_t)namesize; nvh->nvh_dsize = (uint32_t)vsize; - bcopy(name, nvh->nvh_name, namesize); + memcpy(nvh->nvh_name, name, namesize); /* Add header first. */ if (ebuf_add_tail(nv->nv_ebuf, nvh, NVH_HSIZE(nvh)) == -1) { --- sbin/hastd/proto.c.orig +++ sbin/hastd/proto.c @@ -281,7 +281,6 @@ int proto_connection_send(const struct proto_conn *conn, struct proto_conn *mconn) { - const char *protoname; int ret, fd; PJDLOG_ASSERT(conn != NULL); @@ -293,11 +292,9 @@ PJDLOG_ASSERT(mconn->pc_proto != NULL); fd = proto_descriptor(mconn); PJDLOG_ASSERT(fd >= 0); - protoname = mconn->pc_proto->prt_name; - PJDLOG_ASSERT(protoname != NULL); ret = conn->pc_proto->prt_send(conn->pc_ctx, - (const unsigned char *)protoname, strlen(protoname) + 1, fd); + mconn->pc_proto->prt_name, sizeof(mconn->pc_proto->prt_name), fd); proto_close(mconn); if (ret != 0) { errno = ret; @@ -310,7 +307,7 @@ proto_connection_recv(const struct proto_conn *conn, bool client, struct proto_conn **newconnp) { - char protoname[128]; + char protoname[sizeof(conn->pc_proto->prt_name)]; struct proto *proto; struct proto_conn *newconn; int ret, fd; @@ -321,10 +318,8 @@ PJDLOG_ASSERT(conn->pc_proto->prt_recv != NULL); PJDLOG_ASSERT(newconnp != NULL); - bzero(protoname, sizeof(protoname)); - - ret = conn->pc_proto->prt_recv(conn->pc_ctx, (unsigned char *)protoname, - sizeof(protoname) - 1, &fd); + ret = conn->pc_proto->prt_recv(conn->pc_ctx, protoname, + sizeof(protoname), &fd); if (ret != 0) { errno = ret; return (-1); @@ -333,7 +328,7 @@ PJDLOG_ASSERT(fd >= 0); TAILQ_FOREACH(proto, &protos, prt_next) { - if (strcmp(proto->prt_name, protoname) == 0) + if (memcmp(proto->prt_name, protoname, sizeof(protoname)) == 0) break; } if (proto == NULL) { --- sbin/hastd/proto_impl.h.orig +++ sbin/hastd/proto_impl.h @@ -53,7 +53,7 @@ typedef void prt_close_t(void *); struct proto { - const char *prt_name; + char prt_name[4]; prt_client_t *prt_client; prt_connect_t *prt_connect; prt_connect_wait_t *prt_connect_wait; --- sbin/hastd/proto_socketpair.c.orig +++ sbin/hastd/proto_socketpair.c @@ -219,7 +219,7 @@ } static struct proto sp_proto = { - .prt_name = "socketpair", + .prt_name = "skp", .prt_client = sp_client, .prt_send = sp_send, .prt_recv = sp_recv,