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 <[email protected]>
  • Loading branch information
shrikant1407 committed Sep 27, 2024
1 parent eadda88 commit 68f4d91
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 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 @@ -1314,7 +1316,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 +1342,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 68f4d91

Please sign in to comment.