diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2016-11-23 10:28:26 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2016-11-23 11:06:48 +0200 |
commit | 9e8c97a1d22a6bf42131313c1dc39f73b1aaa0c5 (patch) | |
tree | 02624d1cafd8bb02bc31a908dc9f9586ed2092a2 | |
parent | ca407bf38ec83b6b991537233963a14b79a5821e (diff) | |
download | rpm-9e8c97a1d22a6bf42131313c1dc39f73b1aaa0c5.tar.gz |
Refactor headerRead() to use hdrblobRead() + hdrblobImport()
Whee, another lets-read-and-parse-a-header copy-slop variant bites the dust.
Preserving the traditional quiet-on-errors behavior, it's actually required
for reading header lists, since there's no clean way to handle EOF
currently.
-rw-r--r-- | lib/header.c | 50 |
1 files changed, 5 insertions, 45 deletions
diff --git a/lib/header.c b/lib/header.c index cc90496a4..18b0163d5 100644 --- a/lib/header.c +++ b/lib/header.c @@ -1027,54 +1027,14 @@ Header headerCopyLoad(const void * uh) Header headerRead(FD_t fd, int magicp) { - int32_t block[4]; - int32_t * ei = NULL; - int32_t il; - int32_t dl; Header h = NULL; - unsigned int len, blen; - - if (magicp == HEADER_MAGIC_YES) { - int32_t magic; - - if (Freadall(fd, block, 4*sizeof(*block)) != 4*sizeof(*block)) - goto exit; - - magic = block[0]; - - if (memcmp(&magic, rpm_header_magic, sizeof(magic))) - goto exit; - - il = ntohl(block[2]); - dl = ntohl(block[3]); - } else { - if (Freadall(fd, block, 2*sizeof(*block)) != 2*sizeof(*block)) - goto exit; - - il = ntohl(block[0]); - dl = ntohl(block[1]); - } - - blen = (il * sizeof(struct entryInfo_s)) + dl; - len = sizeof(il) + sizeof(dl) + blen; - - /* Sanity checks on header intro. */ - if (hdrchkTags(il) || hdrchkData(dl) || len > headerMaxbytes) - goto exit; - - ei = xmalloc(len); - ei[0] = htonl(il); - ei[1] = htonl(dl); + struct hdrblob_s blob; + char *buf = NULL; - if (Freadall(fd, (char *)&ei[2], blen) != blen) - goto exit; - - h = headerImport(ei, len, 0); + if (hdrblobRead(fd, magicp, 0, 0, &blob, &buf) == RPMRC_OK) + hdrblobImport(&blob, 0, &h, &buf); -exit: - if (h == NULL && ei != NULL) { - free(ei); - } + free(buf); return h; } |