* @param pe header physical entry pointer (swapped)
* @param dataStart header data
* @param regionid region offset
- * @return no. bytes of data in region
+ * @return no. bytes of data in region, -1 on error
*/
static int regionSwab(/*@null@*/ struct indexEntry * entry, int il, int dl,
const struct entryInfo * pe, char * dataStart, int regionid)
ie.info.tag = ntohl(pe->tag);
ie.info.type = ntohl(pe->type);
+ if (ie.info.type < RPM_MIN_TYPE || ie.info.type > RPM_MAX_TYPE)
+ return -1;
ie.info.count = ntohl(pe->count);
ie.info.offset = ntohl(pe->offset);
ie.data = t = dataStart + ie.info.offset;
* @retval p address of data (or NULL)
* @retval c address of count (or NULL)
* @param minMem string pointers refer to header memory?
+ * @return 1 on success, otherwise error.
*/
-static void copyEntry(const struct indexEntry * entry,
+static int copyEntry(const struct indexEntry * entry,
/*@null@*/ /*@out@*/ int_32 * type,
/*@null@*/ /*@out@*/ const void ** p,
/*@null@*/ /*@out@*/ int_32 * c,
/*@modifies *type, *p, *c @*/
{
int_32 count = entry->info.count;
+ int rc = 1; /* XXX 1 on success. */
if (p)
switch (entry->info.type) {
dataStart = (char *) memcpy(pe + ril, dataStart,
(entry->rdlen + REGION_TAG_COUNT));
- (void) regionSwab(NULL, ril, 0, pe, dataStart, 0);
+ rc = regionSwab(NULL, ril, 0, pe, dataStart, 0);
+ /* XXX 1 on success. */
+ rc = (rc < 0) ? 0 : 1;
} else {
count = entry->length;
*p = (!minMem
}
if (type) *type = entry->info.type;
if (c) *c = count;
+ return rc;
}
/**
{
Header h = hi->h;
int slot = hi->next_index;
- struct indexEntry * entry = NULL;;
+ struct indexEntry * entry = NULL;
+ int rc;
for (slot = hi->next_index; slot < h->indexUsed; slot++) {
entry = h->index + slot;
if (tag)
*tag = entry->info.tag;
- copyEntry(entry, type, p, c, 0);
+ rc = copyEntry(entry, type, p, c, 0);
- return 1;
+ /* XXX 1 on success */
+ return ((rc == 1) ? 1 : 0);
}
static int indexCmp(const void *avp, const void *bvp) /*@*/
entry->data = pe;
entry->length = pvlen - sizeof(il) - sizeof(dl);
rdlen = regionSwab(entry+1, il, 0, pe, dataStart, entry->info.offset);
+ if (rdlen < 0) goto errxit;
entry->rdlen = rdlen;
assert(rdlen == dl);
entry->data = pe;
entry->length = pvlen - sizeof(il) - sizeof(dl);
rdlen = regionSwab(entry+1, ril-1, 0, pe+1, dataStart, entry->info.offset);
+ if (rdlen < 0) goto errxit;
entry->rdlen = rdlen;
if (ril < h->indexUsed) {
struct indexEntry * newEntry = entry + ril;
int ne = (h->indexUsed - ril);
int rid = entry->info.offset+1;
+ int rc;
/* Load dribble entries from region. */
- rdlen += regionSwab(newEntry, ne, 0, pe+ril, dataStart, rid);
+ rc = regionSwab(newEntry, ne, 0, pe+ril, dataStart, rid);
+ if (rc < 0) goto errxit;
+ rdlen += rc;
{ struct indexEntry * firstEntry = newEntry;
int save = h->indexUsed;
headerSort(h);
return h;
+
+errxit:
+ /*@-usereleased@*/
+ if (h) {
+ if (h->index) free(h->index);
+ /*@-refcounttrans@*/
+ free(h);
+ /*@=refcounttrans@*/
+ h = NULL;
+ }
+ /*@=usereleased@*/
+ /*@-refcounttrans@*/
+ return h;
+ /*@=refcounttrans@*/
}
Header headerCopyLoad(void *uh)
}
#endif
-static /*@only@*/ void * doHeaderUnload(Header h, /*@out@*/ int * lengthPtr)
+static /*@only@*/ /*@null@*/ void * doHeaderUnload(Header h,
+ /*@out@*/ int * lengthPtr)
/*@modifies h, *lengthPtr @*/
{
- int_32 * ei;
+ int_32 * ei = NULL;
struct entryInfo * pe;
char * dataStart;
char * te;
rdlen += entry->info.count;
count = regionSwab(NULL, ril, 0, pe, t, 0);
+ if (count < 0) goto errxit;
assert(count == rdlen);
} else {
te += entry->info.count + drlen;
count = regionSwab(NULL, ril, 0, pe, t, 0);
+ if (count < 0) goto errxit;
assert(count == rdlen+entry->info.count+drlen);
}
h->sorted = 0;
headerSort(h);
- return (void *)ei;
+ return (void *) ei;
+
+errxit:
+ /*@-usereleased@*/
+ if (ei) {
+ free(ei);
+ ei = NULL;
+ }
+ /*@=usereleased@*/
+ return (void *) ei;
}
-void *headerUnload(Header h)
+void * headerUnload(Header h)
{
int length;
void * uh = doHeaderUnload(h, &length);
/*@-onlytrans@*/
void * uh = doHeaderUnload(h, &length);
+ if (uh == NULL)
+ return NULL;
headerFree(h);
/*@=onlytrans@*/
nh = headerLoad(uh);
if (nh == NULL) {
free(uh);
- return nh;
+ return NULL;
}
if (nh->region_allocated)
free(uh);
if (h == NULL)
return 1;
uh = doHeaderUnload(h, &length);
+ if (uh == NULL)
+ return 1;
switch (magicp) {
case HEADER_MAGIC_YES:
nb = Fwrite(header_magic, sizeof(char), sizeof(header_magic), fd);
int_32 *c)
{
struct indexEntry * entry;
+ int rc;
if (p == NULL) return headerIsEntry(h, tag);
return 0;
}
- copyEntry(entry, type, p, c, 0);
+ rc = copyEntry(entry, type, p, c, 0);
- return 1;
+ /* XXX 1 on success */
+ return ((rc == 1) ? 1 : 0);
}
/**
/*@modifies *type, *p, *c @*/
{
struct indexEntry * entry;
+ int rc = 0;
/* First find the tag */
entry = findEntry(h, tag, RPM_NULL_TYPE);
/*@=dependenttrans@*/
break;
default:
- copyEntry(entry, type, p, c, minMem);
+ rc = copyEntry(entry, type, p, c, minMem);
break;
}
- return 1;
+ /* XXX 1 on success */
+ return ((rc == 1) ? 1 : 0);
}
int headerGetEntryMinMemory(Header h, int_32 tag, int_32 *type, const void **p,
goto exit;
}
- /*@-nullpass@*/
(void) headerNVR(h, NULL, &pkgVersion, &pkgRelease);
- /*@=nullpass@*/
goodRelease = goodVersion = 1;
sigset_t signalMask;
void * uh;
size_t uhlen;
- int rc;
+ int rc = EINVAL; /* XXX W2DO? */
int xx;
if (_noDirTokens)
uhlen = headerSizeof(h, HEADER_MAGIC_NO);
uh = headerUnload(h);
- blockSignals(dbi->dbi_rpmdb, &signalMask);
- rc = dbiPut(dbi, dbcursor, &offset, sizeof(offset), uh, uhlen, 0);
- xx = dbiSync(dbi, 0);
- unblockSignals(dbi->dbi_rpmdb, &signalMask);
- free(uh);
-
+ if (uh) {
+ blockSignals(dbi->dbi_rpmdb, &signalMask);
+ rc = dbiPut(dbi, dbcursor, &offset, sizeof(offset), uh, uhlen, 0);
+ xx = dbiSync(dbi, 0);
+ unblockSignals(dbi->dbi_rpmdb, &signalMask);
+ free(uh);
+ }
return rc;
}
mi->mi_h = NULL;
}
- mi->mi_h = (uh ? headerCopyLoad(uh) : NULL);
+ /* Is this the end of the iteration? */
+ if (uh == NULL)
+ goto exit;
+
+ mi->mi_h = headerCopyLoad(uh);
/* XXX db1 with hybrid, simulated db interface on falloc.c needs free. */
- if (dbi->dbi_api <= 1) uh = _free(uh);
+ if (dbi->dbi_api == 1) uh = _free(uh);
- if (mi->mi_h && mi->mi_release) {
+ /* Did the header load correctly? */
+ if (mi->mi_h == NULL) {
+ rpmError(RPMERR_BADHEADER,
+ _("rpmdb: damaged header instance #%u retrieved, skipping.\n"),
+ mi->mi_offset);
+ goto top;
+ }
+
+ if (mi->mi_release) {
const char * release;
- /*@-nullpass@*/
(void) headerNVR(mi->mi_h, NULL, NULL, &release);
- /*@=nullpass@*/
if (mi->mi_release && strcmp(mi->mi_release, release))
goto top;
}
- if (mi->mi_h && mi->mi_version) {
+ if (mi->mi_version) {
const char * version;
- /*@-nullpass@*/
(void) headerNVR(mi->mi_h, NULL, &version, NULL);
- /*@=nullpass@*/
if (mi->mi_version && strcmp(mi->mi_version, version))
goto top;
}
#ifdef NOTNOW
if (mi->mi_h) {
const char *n, *v, *r;
- /*@-nullpass@*/
headerNVR(mi->mi_h, &n, &v, &r);
- /*@=nullpass@*/
rpmMessage(RPMMESS_DEBUG, "%s-%s-%s at 0x%x, h %p\n", n, v, r,
mi->mi_offset, mi->mi_h);
}