diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-12-24 07:51:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-12-24 07:51:48 +0000 |
commit | 8d843cc9cc0e989d3929f204f77223cd08730c7a (patch) | |
tree | 1fcba17d10325d9d7ccb68b2eb48cd9bbba6a534 /src/nvme/nbft.c | |
parent | Releasing debian version 1.5-3. (diff) | |
download | libnvme-8d843cc9cc0e989d3929f204f77223cd08730c7a.tar.xz libnvme-8d843cc9cc0e989d3929f204f77223cd08730c7a.zip |
Merging upstream version 1.7.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/nvme/nbft.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/nvme/nbft.c b/src/nvme/nbft.c index a1e17cd..2c87088 100644 --- a/src/nvme/nbft.c +++ b/src/nvme/nbft.c @@ -33,17 +33,15 @@ static __u8 csum(const __u8 *buffer, ssize_t length) static void format_ip_addr(char *buf, size_t buflen, __u8 *addr) { - struct in6_addr *addr_ipv6; + struct in6_addr addr_ipv6; - addr_ipv6 = (struct in6_addr *)addr; - if (addr_ipv6->s6_addr32[0] == 0 && - addr_ipv6->s6_addr32[1] == 0 && - ntohl(addr_ipv6->s6_addr32[2]) == 0xffff) + memcpy(&addr_ipv6, addr, sizeof(addr_ipv6)); + if (IN6_IS_ADDR_V4MAPPED(&addr_ipv6)) /* ipv4 */ - inet_ntop(AF_INET, &(addr_ipv6->s6_addr32[3]), buf, buflen); + inet_ntop(AF_INET, &addr_ipv6.s6_addr32[3], buf, buflen); else /* ipv6 */ - inet_ntop(AF_INET6, addr_ipv6, buf, buflen); + inet_ntop(AF_INET6, &addr_ipv6, buf, buflen); } static bool in_heap(struct nbft_header *header, struct nbft_heap_obj obj) @@ -199,15 +197,15 @@ static int read_ssns(struct nbft_info *nbft, verify(raw_ssns->structure_id == NBFT_DESC_SSNS, "invalid ID in SSNS descriptor"); + /* verify transport type */ + verify(raw_ssns->trtype == NBFT_TRTYPE_TCP, + "invalid transport type in SSNS descriptor"); + ssns = calloc(1, sizeof(*ssns)); if (!ssns) return -ENOMEM; ssns->index = le16_to_cpu(raw_ssns->index); - - /* transport type */ - verify(raw_ssns->trtype == NBFT_TRTYPE_TCP, - "invalid transport type in SSNS descriptor"); strncpy(ssns->transport, trtype_to_string(raw_ssns->trtype), sizeof(ssns->transport)); /* transport specific flags */ @@ -413,26 +411,29 @@ static int read_discovery(struct nbft_info *nbft, struct nbft_discovery *raw_discovery, struct nbft_info_discovery **d) { - struct nbft_info_discovery *discovery; + struct nbft_info_discovery *discovery = NULL; struct nbft_header *header = (struct nbft_header *)nbft->raw_nbft; + int r = -EINVAL; if (!(raw_discovery->flags & NBFT_DISCOVERY_VALID)) - return -EINVAL; + goto error; verify(raw_discovery->structure_id == NBFT_DESC_DISCOVERY, "invalid ID in discovery descriptor"); discovery = calloc(1, sizeof(struct nbft_info_discovery)); - if (!discovery) - return -ENOMEM; + if (!discovery) { + r = -ENOMEM; + goto error; + } discovery->index = raw_discovery->index; if (get_heap_obj(raw_discovery, discovery_ctrl_addr_obj, 1, &discovery->uri)) - return -EINVAL; + goto error; if (get_heap_obj(raw_discovery, discovery_ctrl_nqn_obj, 1, &discovery->nqn)) - return -EINVAL; + goto error; discovery->hfi = hfi_from_index(nbft, raw_discovery->hfi_index); if (raw_discovery->hfi_index && !discovery->hfi) @@ -447,7 +448,12 @@ static int read_discovery(struct nbft_info *nbft, nbft->filename, discovery->index); *d = discovery; - return 0; + r = 0; + +error: + if (r) + free(discovery); + return r; } static int read_security(struct nbft_info *nbft, |