diff options
Diffstat (limited to 'usr.sbin/dhcpd/sync.c')
-rw-r--r-- | usr.sbin/dhcpd/sync.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/usr.sbin/dhcpd/sync.c b/usr.sbin/dhcpd/sync.c index d17455e8fb9..1f701f60d46 100644 --- a/usr.sbin/dhcpd/sync.c +++ b/usr.sbin/dhcpd/sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sync.c,v 1.23 2017/02/13 23:04:05 krw Exp $ */ +/* $OpenBSD: sync.c,v 1.24 2022/01/05 11:01:59 tb Exp $ */ /* * Copyright (c) 2008 Bob Beck <beck@openbsd.org> @@ -393,7 +393,7 @@ sync_lease(struct lease *lease) char pad[DHCP_ALIGNBYTES]; u_int16_t leaselen, padlen; int i = 0; - HMAC_CTX ctx; + HMAC_CTX *ctx; u_int hmac_len; if (sync_key == NULL) @@ -403,8 +403,10 @@ sync_lease(struct lease *lease) memset(&lv, 0, sizeof(lv)); memset(&pad, 0, sizeof(pad)); - HMAC_CTX_init(&ctx); - HMAC_Init(&ctx, sync_key, strlen(sync_key), EVP_sha1()); + if ((ctx = HMAC_CTX_new()) == NULL) + goto bad; + if (!HMAC_Init_ex(ctx, sync_key, strlen(sync_key), EVP_sha1(), NULL)) + goto bad; leaselen = sizeof(lv); padlen = DHCP_ALIGN(leaselen) - leaselen; @@ -416,7 +418,8 @@ sync_lease(struct lease *lease) hdr.sh_length = htons(sizeof(hdr) + sizeof(lv) + padlen + sizeof(end)); iov[i].iov_base = &hdr; iov[i].iov_len = sizeof(hdr); - HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len); + if (!HMAC_Update(ctx, iov[i].iov_base, iov[i].iov_len)) + goto bad; i++; /* Add single DHCP sync address entry */ @@ -434,12 +437,14 @@ sync_lease(struct lease *lease) piaddr(lease->ip_addr), ntohl(lv.lv_starts), ntohl(lv.lv_ends)); iov[i].iov_base = &lv; iov[i].iov_len = sizeof(lv); - HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len); + if (!HMAC_Update(ctx, iov[i].iov_base, iov[i].iov_len)) + goto bad; i++; iov[i].iov_base = pad; iov[i].iov_len = padlen; - HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len); + if (!HMAC_Update(ctx, iov[i].iov_base, iov[i].iov_len)) + goto bad; i++; /* Add end marker */ @@ -447,12 +452,16 @@ sync_lease(struct lease *lease) end.st_length = htons(sizeof(end)); iov[i].iov_base = &end; iov[i].iov_len = sizeof(end); - HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len); + if (!HMAC_Update(ctx, iov[i].iov_base, iov[i].iov_len)) + goto bad; i++; - HMAC_Final(&ctx, hdr.sh_hmac, &hmac_len); + if (!HMAC_Final(ctx, hdr.sh_hmac, &hmac_len)) + goto bad; /* Send message to the target hosts */ sync_send(iov, i); - HMAC_CTX_cleanup(&ctx); + + bad: + HMAC_CTX_free(ctx); } |