Skip to content

Commit

Permalink
Refactor and improve error handling in network address parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Shrikant Temburwar <shrikant.temburwar@intel.com>
  • Loading branch information
shrikant1407 committed Sep 27, 2024
1 parent eadda88 commit c9eb82d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/fdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,8 @@ bool parse_manufacturer_address(char *buffer, size_t buffer_sz, bool *tls,
index++;
}

transport_prot[index] = '\0';

// parse separator "://"
if (buffer[index] != ':' || buffer[index + 1] != '/' ||
buffer[index + 2] != '/') {
Expand Down Expand Up @@ -1099,8 +1101,7 @@ bool parse_manufacturer_address(char *buffer, size_t buffer_sz, bool *tls,
LOG(LOG_INFO, "%s is an ipv6 address\n", mfg_dns);
is_ipv6 = true;
} else {
LOG(LOG_DEBUG, "%s is an unknown address format %d\n", mfg_dns,
ip_info);
LOG(LOG_INFO, "%s is a DNS name\n", mfg_dns);
}

*mfg_ip = fdo_ipaddress_alloc();
Expand Down Expand Up @@ -1314,7 +1315,7 @@ static bool _STATE_DI(void)
if (use_mfg_addr_bin) {
fsize =
fdo_blob_size((char *)MANUFACTURER_ADDR, FDO_SDK_RAW_DATA);
if (fsize > 0) {
if (fsize < FDO_MAX_STR_SIZE && fsize > 0) {
buffer = fdo_alloc(fsize + 1);
if (buffer == NULL) {
LOG(LOG_ERROR, "malloc failed\n");
Expand All @@ -1340,7 +1341,7 @@ static bool _STATE_DI(void)
}
} else {
LOG(LOG_ERROR,
"Manufacturer Network address file is empty.\n");
"Invalid Manufacturer Network address.\n");
goto end;
}
} else {
Expand Down
1 change: 0 additions & 1 deletion lib/fdonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ bool resolve_dn(char *dn, fdo_ip_address_t **ip, uint16_t port, bool tls,
if (connect_ok == -1) {
LOG(LOG_ERROR, "Failed to connect to server: "
"retrying...\n");
// curl_easy_cleanup(curl);
}
iter++;
}
Expand Down
4 changes: 3 additions & 1 deletion network/network_if_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,9 @@ int check_ip_version(char *ip_addr)
struct addrinfo hint, *res = NULL;
int ret = -1;

memset(&hint, '\0', sizeof hint);
if (memset_s(&hint, sizeof hint, 0)) {
goto end;
}

hint.ai_family = PF_UNSPEC;
hint.ai_flags = AI_NUMERICHOST;
Expand Down

0 comments on commit c9eb82d

Please sign in to comment.