handle empty files as bad magic, not read errors
authorewt <devnull@localhost>
Mon, 3 Nov 1997 20:17:45 +0000 (20:17 +0000)
committerewt <devnull@localhost>
Mon, 3 Nov 1997 20:17:45 +0000 (20:17 +0000)
CVS patchset: 1891
CVS date: 1997/11/03 20:17:45

lib/package.c

index 0dd3a4d..feee098 100644 (file)
@@ -2,6 +2,7 @@
 #include <netinet/in.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 #include <unistd.h>
 
 #include "errno.h"
@@ -29,13 +30,17 @@ static int readPackageHeaders(int fd, struct rpmlead * leadPtr,
     struct oldrpmlead * oldLead;
     int_8 arch;
     int isSource;
+    struct stat sb;
 
     hdr = hdrPtr ? hdrPtr : &hdrBlock;
     lead = leadPtr ? leadPtr : &leadBlock;
 
     oldLead = (struct oldrpmlead *) lead;
 
-    if (readLead(fd, lead)) {
+    fstat(fd, &sb);
+    if (sb.st_size < 4) return 1;
+
+    if ((rc = readLead(fd, lead))) {
        return 2;
     }