| 7153 | } |
| 7154 | |
| 7155 | static int |
| 7156 | defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, |
| 7157 | XML_Bool isId, const XML_Char *value, XML_Parser parser) { |
| 7158 | DEFAULT_ATTRIBUTE *att; |
| 7159 | if (value || isId) { |
| 7160 | /* The handling of default attributes gets messed up if we have |
| 7161 | a default which duplicates a non-default. */ |
| 7162 | int i; |
| 7163 | for (i = 0; i < type->nDefaultAtts; i++) |
| 7164 | if (attId == type->defaultAtts[i].id) |
| 7165 | return 1; |
| 7166 | if (isId && ! type->idAtt && ! attId->xmlns) |
| 7167 | type->idAtt = attId; |
| 7168 | } |
| 7169 | if (type->nDefaultAtts == type->allocDefaultAtts) { |
| 7170 | if (type->allocDefaultAtts == 0) { |
| 7171 | type->allocDefaultAtts = 8; |
| 7172 | type->defaultAtts |
| 7173 | = MALLOC(parser, type->allocDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); |
| 7174 | if (! type->defaultAtts) { |
| 7175 | type->allocDefaultAtts = 0; |
| 7176 | return 0; |
| 7177 | } |
| 7178 | } else { |
| 7179 | DEFAULT_ATTRIBUTE *temp; |
| 7180 | |
| 7181 | /* Detect and prevent integer overflow */ |
| 7182 | if (type->allocDefaultAtts > INT_MAX / 2) { |
| 7183 | return 0; |
| 7184 | } |
| 7185 | |
| 7186 | int count = type->allocDefaultAtts * 2; |
| 7187 | |
| 7188 | /* Detect and prevent integer overflow. |
| 7189 | * The preprocessor guard addresses the "always false" warning |
| 7190 | * from -Wtype-limits on platforms where |
| 7191 | * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ |
| 7192 | #if UINT_MAX >= SIZE_MAX |
| 7193 | if ((unsigned)count > (size_t)(-1) / sizeof(DEFAULT_ATTRIBUTE)) { |
| 7194 | return 0; |
| 7195 | } |
| 7196 | #endif |
| 7197 | |
| 7198 | temp = REALLOC(parser, type->defaultAtts, |
| 7199 | (count * sizeof(DEFAULT_ATTRIBUTE))); |
| 7200 | if (temp == NULL) |
| 7201 | return 0; |
| 7202 | type->allocDefaultAtts = count; |
| 7203 | type->defaultAtts = temp; |
| 7204 | } |
| 7205 | } |
| 7206 | att = type->defaultAtts + type->nDefaultAtts; |
| 7207 | att->id = attId; |
| 7208 | att->value = value; |
| 7209 | att->isCdata = isCdata; |
| 7210 | if (! isCdata) |
| 7211 | attId->maybeTokenized = XML_TRUE; |
| 7212 | type->nDefaultAtts += 1; |
no outgoing calls
no test coverage detected
searching dependent graphs…