datapath-windows/ovsext/Netlink/Netlink.c
/*
 * ---------------------------------------------------------------------------
 * Validate the netlink attribute against the policy
 * ---------------------------------------------------------------------------
 */
Validate the netlink attribute against the policy
Validate the netlink attribute against the policy
BOOLEAN
NlAttrValidate(const PNL_ATTR nla, const PNL_POLICY policy)
{
    UINT32 minLen;
    UINT32 maxLen;
    UINT32 len;
    BOOLEAN ret = FALSE;
    if ((policy->type == NL_A_NO_ATTR) ||
        (policy->type == NL_A_VAR_LEN) ||
        (policy->type == NL_A_NESTED)) {
        ret = TRUE;
        goto done;
    }
    minLen = policy->minLen;
    if (!minLen) {
        minLen = NlAttrMinLen(policy->type);
    }
    maxLen = policy->maxLen;
    if (!maxLen) {
        maxLen = NlAttrMaxLen(policy->type);
    }
    len = NlAttrGetSize(nla);
    if (len < minLen || len > maxLen) {
        OVS_LOG_WARN("Attribute: %p, len: %d, not in valid range, "
                     "min: %d, max: %d", nla, len, minLen, maxLen);
        goto done;
    }
    if (policy->type == NL_A_STRING) {
        if (((PCHAR) nla)[nla->nlaLen - 1]) {
            OVS_LOG_WARN("Attributes %p lacks null at the end", nla);
            goto done;
        }
        if (memchr(nla + 1, '\0', len - 1) != NULL) {
            OVS_LOG_WARN("Attributes %p has bad length", nla);
            goto done;
        }
    }
    ret = TRUE;
done:
    return ret;
}
BOOLEAN NlAttrValidate ( const PNL_ATTR nla , const PNL_POLICY policy ) { UINT32 minLen ; UINT32 maxLen ; UINT32 len ; BOOLEAN ret = FALSE ; if ( ( policy -> type == NL_A_NO_ATTR ) || ( policy -> type == NL_A_VAR_LEN ) || ( policy -> type == NL_A_NESTED ) ) { ret = TRUE ; goto done ; } minLen = policy -> minLen ; if ( ! minLen ) { minLen = NlAttrMinLen ( policy -> type ) ; } maxLen = policy -> maxLen ; if ( ! maxLen ) { maxLen = NlAttrMaxLen ( policy -> type ) ; } len = NlAttrGetSize ( nla ) ; if ( len < minLen || len > maxLen ) { OVS_LOG_WARN ( " " " " , nla , len , minLen , maxLen ) ; goto done ; } if ( policy -> type == NL_A_STRING ) { if ( ( ( PCHAR ) nla ) [ nla -> nlaLen - 1 ] ) { OVS_LOG_WARN ( " " , nla ) ; goto done ; } if ( memchr ( nla + 1 , ' \0 ' , len - 1 ) != NULL ) { OVS_LOG_WARN ( " " , nla ) ; goto done ; } } ret = TRUE ; done : return ret ; }
Validate the netlink attribute against the policy
Validate the netlink attribute against the policy
/* Do not validate anything for attributes of type var length */ /* Figure out min and max length. */ /* Verify length. */ /* Strings must be null terminated and must not have embedded nulls. */