Modify eu-strip option to perform strip in post script of rpm package & add option...
[platform/upstream/rpm.git] / lib / header.c
index 023c6e3..90079f3 100644 (file)
 
 #include "system.h"
 #include <netdb.h>
+#include <errno.h>
 #include <rpm/rpmtypes.h>
 #include <rpm/rpmstring.h>
 #include "lib/header_internal.h"
 #include "lib/misc.h"                  /* tag function proto */
 
+#include <errno.h>
 #include "debug.h"
 
 /** \ingroup header
@@ -199,7 +201,7 @@ int headerVerifyInfo(int il, int dl, const void * pev, void * iv, int negate)
            return i;
        if (hdrchkAlign(info->type, info->offset))
            return i;
-       if (!negate && hdrchkRange(dl, info->offset))
+       if (hdrchkRange(dl, info->offset))
            return i;
        if (hdrchkData(info->count))
            return i;
@@ -828,10 +830,13 @@ Header headerImport(void * blob, unsigned int bsize, headerImportFlags flags)
 
        entry->info.type = htonl(pe->type);
        entry->info.count = htonl(pe->count);
+       entry->info.tag = htonl(pe->tag);
 
-       if (hdrchkType(entry->info.type))
+       if (!ENTRY_IS_REGION(entry))
+           goto errxit;
+       if (entry->info.type != REGION_TAG_TYPE)
            goto errxit;
-       if (hdrchkTags(entry->info.count))
+       if (entry->info.count != REGION_TAG_COUNT)
            goto errxit;
 
        {   int off = ntohl(pe->offset);
@@ -847,7 +852,6 @@ Header headerImport(void * blob, unsigned int bsize, headerImportFlags flags)
                ril = rdl/sizeof(*pe);
                if (hdrchkTags(ril) || hdrchkData(rdl))
                    goto errxit;
-               entry->info.tag = htonl(pe->tag);
            } else {
                ril = il;
                rdl = (ril * sizeof(struct entryInfo_s));
@@ -962,7 +966,7 @@ Header headerRead(FD_t fd, int magicp)
     if (magicp == HEADER_MAGIC_YES) {
        int32_t magic;
 
-       if (Fread(block, 1, 4*sizeof(*block), fd) != 4*sizeof(*block))
+       if (Freadall(fd, block, 4*sizeof(*block)) != 4*sizeof(*block))
            goto exit;
 
        magic = block[0];
@@ -973,7 +977,7 @@ Header headerRead(FD_t fd, int magicp)
        il = ntohl(block[2]);
        dl = ntohl(block[3]);
     } else {
-       if (Fread(block, 1, 2*sizeof(*block), fd) != 2*sizeof(*block))
+       if (Freadall(fd, block, 2*sizeof(*block)) != 2*sizeof(*block))
            goto exit;
 
        il = ntohl(block[0]);
@@ -991,7 +995,7 @@ Header headerRead(FD_t fd, int magicp)
     ei[0] = htonl(il);
     ei[1] = htonl(dl);
 
-    if (Fread((char *)&ei[2], 1, blen, fd) != blen)
+    if (Freadall(fd, (char *)&ei[2], blen) != blen)
        goto exit;
     
     h = headerImport(ei, len, 0);
@@ -1403,7 +1407,7 @@ static int intAddEntry(Header h, rpmtd td)
 {
     indexEntry entry;
     rpm_data_t data;
-    int length;
+    int length = 0;
 
     /* Count must always be >= 1 for headerAddEntry. */
     if (td->count <= 0)
@@ -1414,9 +1418,8 @@ static int intAddEntry(Header h, rpmtd td)
     if (hdrchkData(td->count))
        return 0;
 
-    length = 0;
     data = grabData(td->type, td->data, td->count, &length);
-    if (data == NULL || length <= 0)
+    if (data == NULL)
        return 0;
 
     /* Allocate more index space if necessary */
@@ -1636,16 +1639,15 @@ int headerMod(Header h, rpmtd td)
     indexEntry entry;
     rpm_data_t oldData;
     rpm_data_t data;
-    int length;
+    int length = 0;
 
     /* First find the tag */
     entry = findEntry(h, td->tag, td->type);
     if (!entry)
        return 0;
 
-    length = 0;
     data = grabData(td->type, td->data, td->count, &length);
-    if (data == NULL || length <= 0)
+    if (data == NULL)
        return 0;
 
     /* make sure entry points to the first occurence of this tag */
@@ -1745,3 +1747,29 @@ void headerSetInstance(Header h, unsigned int instance)
     h->instance = instance;
 }    
 
+#define RETRY_ERROR(_err) \
+    ((_err) == EINTR || (_err) == EAGAIN || (_err) == EWOULDBLOCK)
+
+ssize_t Freadall(FD_t fd, void * buf, ssize_t size)
+{
+    ssize_t total = 0;
+    ssize_t nb = 0;
+    char * bufp = buf;
+
+    while (total < size) {
+       nb = Fread(bufp, 1, size - total, fd);
+
+       if (nb == 0 || (nb < 0 && !RETRY_ERROR(errno))) {
+           total = nb;
+           break;
+       }
+
+       if (nb > 0) {
+           bufp += nb;
+           total += nb;
+       }
+    }
+
+    return total;
+}
+