| 3981 | */ |
| 3982 | |
| 3983 | int /* O - 1 if valid, 0 otherwise */ |
| 3984 | ippValidateAttribute( |
| 3985 | ipp_attribute_t *attr) /* I - Attribute */ |
| 3986 | { |
| 3987 | int i; /* Looping var */ |
| 3988 | char scheme[64], /* Scheme from URI */ |
| 3989 | userpass[256], /* Username/password from URI */ |
| 3990 | hostname[256], /* Hostname from URI */ |
| 3991 | resource[1024]; /* Resource from URI */ |
| 3992 | int port, /* Port number from URI */ |
| 3993 | uri_status; /* URI separation status */ |
| 3994 | const char *ptr; /* Pointer into string */ |
| 3995 | ipp_attribute_t *colattr; /* Collection attribute */ |
| 3996 | regex_t re; /* Regular expression */ |
| 3997 | ipp_uchar_t *date; /* Current date value */ |
| 3998 | |
| 3999 | |
| 4000 | /* |
| 4001 | * Skip separators. |
| 4002 | */ |
| 4003 | |
| 4004 | if (!attr->name) |
| 4005 | return (1); |
| 4006 | |
| 4007 | /* |
| 4008 | * Validate the attribute name. |
| 4009 | */ |
| 4010 | |
| 4011 | for (ptr = attr->name; *ptr; ptr ++) |
| 4012 | if (!isalnum(*ptr & 255) && *ptr != '-' && *ptr != '.' && *ptr != '_') |
| 4013 | break; |
| 4014 | |
| 4015 | if (*ptr || ptr == attr->name) |
| 4016 | { |
| 4017 | ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad attribute name - invalid character (RFC 8011 section 5.1.4)."), attr->name); |
| 4018 | return (0); |
| 4019 | } |
| 4020 | |
| 4021 | if ((ptr - attr->name) > 255) |
| 4022 | { |
| 4023 | ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad attribute name - bad length %d (RFC 8011 section 5.1.4)."), attr->name, (int)(ptr - attr->name)); |
| 4024 | return (0); |
| 4025 | } |
| 4026 | |
| 4027 | switch (attr->value_tag) |
| 4028 | { |
| 4029 | case IPP_TAG_INTEGER : |
| 4030 | break; |
| 4031 | |
| 4032 | case IPP_TAG_BOOLEAN : |
| 4033 | for (i = 0; i < attr->num_values; i ++) |
| 4034 | { |
| 4035 | if (attr->values[i].boolean != 0 && |
| 4036 | attr->values[i].boolean != 1) |
| 4037 | { |
| 4038 | ipp_set_error(IPP_STATUS_ERROR_BAD_REQUEST, _("\"%s\": Bad boolean value %d (RFC 8011 section 5.1.21)."), attr->name, attr->values[i].boolean); |
| 4039 | return (0); |
| 4040 | } |
no test coverage detected