int headerVerifyInfo(int il, int dl, const void * pev, void * iv, int negate) { entryInfo pe = (entryInfo) pev; entryInfo info = iv; int i; for (i = 0; i < il; i++) { info->tag = ntohl(pe[i].tag); info->type = ntohl(pe[i].type); info->offset = ntohl(pe[i].offset); if (negate) info->offset = -info->offset; info->count = ntohl(pe[i].count); if (hdrchkType(info->type)) return i; if (hdrchkAlign(info->type, info->offset)) return i; if (hdrchkRange(dl, info->offset)) return i; if (hdrchkData(info->count)) return i; } return -1; }
/** \ingroup header * Swap int32_t and int16_t arrays within header region. * * If a header region tag is in the set to be swabbed, as the data for a * a header region is located after all other tag data. * * @param entry header entry * @param il no. of entries * @param dl start no. bytes of data * @param pe header physical entry pointer (swapped) * @param dataStart header data start * @param dataEnd header data end * @param regionid region offset * @param fast use offsets for data sizes if possible * @return no. bytes of data in region, -1 on error */ static int regionSwab(indexEntry entry, int il, int dl, entryInfo pe, unsigned char * dataStart, const unsigned char * dataEnd, int regionid, int fast) { if ((entry != NULL && regionid >= 0) || (entry == NULL && regionid != 0)) return -1; for (; il > 0; il--, pe++) { struct indexEntry_s ie; ie.info.tag = ntohl(pe->tag); ie.info.type = ntohl(pe->type); ie.info.count = ntohl(pe->count); ie.info.offset = ntohl(pe->offset); if (hdrchkType(ie.info.type)) return -1; if (hdrchkData(ie.info.count)) return -1; if (hdrchkData(ie.info.offset)) return -1; if (hdrchkAlign(ie.info.type, ie.info.offset)) return -1; ie.data = dataStart + ie.info.offset; if (dataEnd && (unsigned char *)ie.data >= dataEnd) return -1; if (fast && il > 1) { ie.length = ntohl(pe[1].offset) - ie.info.offset; } else { ie.length = dataLength(ie.info.type, ie.data, ie.info.count, 1, dataEnd); } if (ie.length < 0 || hdrchkData(ie.length)) return -1; ie.rdlen = 0; if (entry) { ie.info.offset = regionid; *entry = ie; /* structure assignment */ entry++; } /* Alignment */ dl += alignDiff(ie.info.type, dl); /* Perform endian conversions */ switch (ntohl(pe->type)) { case RPM_INT64_TYPE: { uint64_t * it = ie.data; for (; ie.info.count > 0; ie.info.count--, it += 1) { if (dataEnd && ((unsigned char *)it) >= dataEnd) return -1; *it = htonll(*it); } } break; case RPM_INT32_TYPE: { int32_t * it = ie.data; for (; ie.info.count > 0; ie.info.count--, it += 1) { if (dataEnd && ((unsigned char *)it) >= dataEnd) return -1; *it = htonl(*it); } } break; case RPM_INT16_TYPE: { int16_t * it = ie.data; for (; ie.info.count > 0; ie.info.count--, it += 1) { if (dataEnd && ((unsigned char *)it) >= dataEnd) return -1; *it = htons(*it); } } break; } dl += ie.length; } return dl; }
/** \ingroup header * Swap int32_t and int16_t arrays within header region. * * If a header region tag is in the set to be swabbed, as the data for a * a header region is located after all other tag data. * * @param entry header entry * @param il no. of entries * @param dl start no. bytes of data * @param pe header physical entry pointer (swapped) * @param dataStart header data start * @param dataEnd header data end * @param regionid region offset * @return no. bytes of data in region, -1 on error */ static int regionSwab(indexEntry entry, int il, int dl, entryInfo pe, unsigned char * dataStart, const unsigned char * dataEnd, int regionid) { for (; il > 0; il--, pe++) { struct indexEntry_s ie; rpmTagType type; ie.info.tag = ntohl(pe->tag); ie.info.type = ntohl(pe->type); ie.info.count = ntohl(pe->count); ie.info.offset = ntohl(pe->offset); if (hdrchkType(ie.info.type)) return -1; if (hdrchkData(ie.info.count)) return -1; if (hdrchkData(ie.info.offset)) return -1; if (hdrchkAlign(ie.info.type, ie.info.offset)) return -1; ie.data = dataStart + ie.info.offset; if (dataEnd && (unsigned char *)ie.data >= dataEnd) return -1; ie.length = dataLength(ie.info.type, ie.data, ie.info.count, 1, dataEnd); if (ie.length < 0 || hdrchkData(ie.length)) return -1; ie.rdlen = 0; if (entry) { ie.info.offset = regionid; *entry = ie; /* structure assignment */ entry++; } /* Alignment */ type = ie.info.type; if (typeSizes[type] > 1) { unsigned diff = typeSizes[type] - (dl % typeSizes[type]); if (diff != typeSizes[type]) { dl += diff; } } /* Perform endian conversions */ switch (ntohl(pe->type)) { case RPM_INT64_TYPE: { uint64_t * it = ie.data; for (; ie.info.count > 0; ie.info.count--, it += 1) { if (dataEnd && ((unsigned char *)it) >= dataEnd) return -1; *it = htonll(*it); } } break; case RPM_INT32_TYPE: { int32_t * it = ie.data; for (; ie.info.count > 0; ie.info.count--, it += 1) { if (dataEnd && ((unsigned char *)it) >= dataEnd) return -1; *it = htonl(*it); } } break; case RPM_INT16_TYPE: { int16_t * it = ie.data; for (; ie.info.count > 0; ie.info.count--, it += 1) { if (dataEnd && ((unsigned char *)it) >= dataEnd) return -1; *it = htons(*it); } } break; } dl += ie.length; } return dl; }