Skip to content

Commit

Permalink
8319382: com/sun/jdi/JdwpAllowTest.java shows failures on AIX if pref…
Browse files Browse the repository at this point in the history
…ixLen of mask is larger than 32 in IPv6 case

Reviewed-by: mbaesken, amenkov
  • Loading branch information
Joachim Kern authored and MBaesken committed Jan 17, 2024
1 parent b891721 commit 22642ff
Showing 1 changed file with 13 additions and 34 deletions.
47 changes: 13 additions & 34 deletions src/jdk.jdwp.agent/share/native/libdt_socket/socketTransport.c
Expand Up @@ -395,18 +395,14 @@ parseAddress(const char *address, struct addrinfo **result) {
return getAddrInfo(address, hostnameLen, port, &hints, result);
}

/*
* Input is sockaddr just because all clients have it.
*/
static void convertIPv4ToIPv6(const struct sockaddr *addr4, struct in6_addr *addr6) {
static void convertIPv4ToIPv6(const struct in_addr *addr4, struct in6_addr *addr6) {
// Implement in a platform-independent way.
// Spec requires in_addr has s_addr member, in6_addr has s6_addr[16] member.
struct in_addr *a4 = &(((struct sockaddr_in*)addr4)->sin_addr);
memset(addr6, 0, sizeof(*addr6)); // for safety

// Mapped address contains 80 zero bits, then 16 "1" bits, then IPv4 address (4 bytes).
addr6->s6_addr[10] = addr6->s6_addr[11] = 0xFF;
memcpy(&(addr6->s6_addr[12]), &(a4->s_addr), 4);
memcpy(&(addr6->s6_addr[12]), &(addr4->s_addr), 4);
}

/*
Expand All @@ -415,37 +411,19 @@ static void convertIPv4ToIPv6(const struct sockaddr *addr4, struct in6_addr *add
*/
static jdwpTransportError
parseAllowedAddr(const char *buffer, struct in6_addr *result, int *isIPv4) {
struct addrinfo hints;
struct addrinfo *addrInfo = NULL;
jdwpTransportError err;

/*
* To parse both IPv4 and IPv6 need to specify AF_UNSPEC family
* (with AF_INET6 IPv4 addresses are not parsed even with AI_V4MAPPED and AI_ALL flags).
*/
memset (&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; // IPv6 or mapped IPv4
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_NUMERICHOST; // only numeric addresses, no resolution

err = getAddrInfo(buffer, strlen(buffer), NULL, &hints, &addrInfo);

if (err != JDWPTRANSPORT_ERROR_NONE) {
return err;
}

if (addrInfo->ai_family == AF_INET6) {
memcpy(result, &(((struct sockaddr_in6 *)(addrInfo->ai_addr))->sin6_addr), sizeof(*result));
struct in_addr addr;
struct in6_addr addr6;
if (inet_pton(AF_INET6, buffer, &addr6) == 1) {
*isIPv4 = 0;
} else { // IPv4 address - convert to mapped IPv6
struct in6_addr addr6;
convertIPv4ToIPv6(addrInfo->ai_addr, &addr6);
memcpy(result, &addr6, sizeof(*result));
} else if (inet_pton(AF_INET, buffer, &addr) == 1) {
// IPv4 address - convert to mapped IPv6
convertIPv4ToIPv6(&addr, &addr6);
*isIPv4 = 1;
} else {
return JDWPTRANSPORT_ERROR_IO_ERROR;
}

dbgsysFreeAddrInfo(addrInfo);
memcpy(result, &addr6, sizeof(*result));

return JDWPTRANSPORT_ERROR_NONE;
}
Expand Down Expand Up @@ -603,7 +581,8 @@ isPeerAllowed(struct sockaddr_storage *peer) {
int i;
// _peers contains IPv6 subnet and mask (IPv4 is converted to mapped IPv6)
if (peer->ss_family == AF_INET) {
convertIPv4ToIPv6((struct sockaddr *)peer, &tmp);
struct in_addr *addr4 = &(((struct sockaddr_in*)peer)->sin_addr);
convertIPv4ToIPv6(addr4, &tmp);
addr6 = &tmp;
} else {
addr6 = &(((struct sockaddr_in6 *)peer)->sin6_addr);
Expand Down

5 comments on commit 22642ff

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoKern65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk22u

@openjdk
Copy link

@openjdk openjdk bot commented on 22642ff Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoKern65 the backport was successfully created on the branch backport-JoKern65-22642ff0 in my personal fork of openjdk/jdk22u. To create a pull request with this backport targeting openjdk/jdk22u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 22642ff0 from the openjdk/jdk repository.

The commit being backported was authored by Joachim Kern on 17 Jan 2024 and was reviewed by Matthias Baesken and Alex Menkov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22u:

$ git fetch https://github.com/openjdk-bots/jdk22u.git backport-JoKern65-22642ff0:backport-JoKern65-22642ff0
$ git checkout backport-JoKern65-22642ff0
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk22u.git backport-JoKern65-22642ff0

⚠️ @JoKern65 You are not yet a collaborator in my fork openjdk-bots/jdk22u. An invite will be sent out and you need to accept it before you can proceed.

@JoKern65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 22642ff Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoKern65 the backport was successfully created on the branch backport-JoKern65-22642ff0 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 22642ff0 from the openjdk/jdk repository.

The commit being backported was authored by Joachim Kern on 17 Jan 2024 and was reviewed by Matthias Baesken and Alex Menkov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-JoKern65-22642ff0:backport-JoKern65-22642ff0
$ git checkout backport-JoKern65-22642ff0
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-JoKern65-22642ff0

⚠️ @JoKern65 You are not yet a collaborator in my fork openjdk-bots/jdk21u-dev. An invite will be sent out and you need to accept it before you can proceed.

Please sign in to comment.