Skip to content

Commit

Permalink
Merge pull request #8628 from tom-cosgrove-arm/ip_len-2.28
Browse files Browse the repository at this point in the history
Backport 2.28: Avoid use of `ip_len` as it clashes with a macro in AIX system headers
  • Loading branch information
bensze01 authored Dec 18, 2023
2 parents 4966eb8 + e1f6d3b commit b80ac7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/mbedtls/net_sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int mbedtls_net_bind(mbedtls_net_context *ctx, const char *bind_ip, const char *
* \param client_ctx Will contain the connected client socket
* \param client_ip Will contain the client IP address, can be NULL
* \param buf_size Size of the client_ip buffer
* \param ip_len Will receive the size of the client IP written,
* \param cip_len Will receive the size of the client IP written,
* can be NULL if client_ip is null
*
* \return 0 if successful, or
Expand All @@ -153,7 +153,7 @@ int mbedtls_net_bind(mbedtls_net_context *ctx, const char *bind_ip, const char *
*/
int mbedtls_net_accept(mbedtls_net_context *bind_ctx,
mbedtls_net_context *client_ctx,
void *client_ip, size_t buf_size, size_t *ip_len);
void *client_ip, size_t buf_size, size_t *cip_len);

/**
* \brief Check and wait for the context to be ready for read/write
Expand Down
14 changes: 7 additions & 7 deletions library/net_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static int net_would_block(const mbedtls_net_context *ctx)
*/
int mbedtls_net_accept(mbedtls_net_context *bind_ctx,
mbedtls_net_context *client_ctx,
void *client_ip, size_t buf_size, size_t *ip_len)
void *client_ip, size_t buf_size, size_t *cip_len)
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
int type;
Expand Down Expand Up @@ -404,22 +404,22 @@ int mbedtls_net_accept(mbedtls_net_context *bind_ctx,
if (client_ip != NULL) {
if (client_addr.ss_family == AF_INET) {
struct sockaddr_in *addr4 = (struct sockaddr_in *) &client_addr;
*ip_len = sizeof(addr4->sin_addr.s_addr);
*cip_len = sizeof(addr4->sin_addr.s_addr);

if (buf_size < *ip_len) {
if (buf_size < *cip_len) {
return MBEDTLS_ERR_NET_BUFFER_TOO_SMALL;
}

memcpy(client_ip, &addr4->sin_addr.s_addr, *ip_len);
memcpy(client_ip, &addr4->sin_addr.s_addr, *cip_len);
} else {
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) &client_addr;
*ip_len = sizeof(addr6->sin6_addr.s6_addr);
*cip_len = sizeof(addr6->sin6_addr.s6_addr);

if (buf_size < *ip_len) {
if (buf_size < *cip_len) {
return MBEDTLS_ERR_NET_BUFFER_TOO_SMALL;
}

memcpy(client_ip, &addr6->sin6_addr.s6_addr, *ip_len);
memcpy(client_ip, &addr6->sin6_addr.s6_addr, *cip_len);
}
}

Expand Down

0 comments on commit b80ac7d

Please sign in to comment.