Skip to content

validate_ip_address method in util.c file does not check for address family mismatch #114

Description

Issue

  • validate_ip_address method in util.c file does not check for address family mismatch
  • Allows incompatible combinations to pass early validation and only fail during runtime when connections are being established.
  • -6 -a 1.2.3.4 & -a ::1 pass early validation but fail during runtime.

Impact

This results in poor user experience with delayed error reporting.

Code

int validate_ip_address(const char *ip_str) 
{
    struct in_addr ipv4_addr;
    struct in6_addr ipv6_addr;

    if (inet_pton(AF_INET, ip_str, &ipv4_addr) == 1) {
        return NO_ERROR;  // Accepts IPv4
    } else if (inet_pton(AF_INET6, ip_str, &ipv6_addr) == 1) {
        return NO_ERROR;  // Accepts IPv6
    }
    return ERROR_ARGS;
}

ntttcp_update_client_info method in util.c file:

if (sc->domain == AF_INET) {
    if (sc->use_client_address) {
        if (inet_pton(AF_INET, sc->client_address, ...) <= 0) {
            // FAILS here if IPv6 address with IPv4 domain
            return ERROR_ARGS;
        }
    }
} else {
    if (sc->use_client_address) {
        if (inet_pton(AF_INET6, sc->client_address, ...) <= 0) {
            // FAILS here if IPv4 address with IPv6 domain
            return ERROR_ARGS;
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions