volser: detect eof in dump stream while reading acl 03/11703/7
authorMichael Meffie <mmeffie@sinenomine.net>
Fri, 30 Jan 2015 17:20:10 +0000 (12:20 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 4 Feb 2016 04:32:05 +0000 (23:32 -0500)
Detect an EOF condition while reading the ACL in a dump stream
and return a restore error, instead of filling the ACL with
0xFF and then failing the restore due to an invalid tag.

Change-Id: If7a71946c81f47ac68ed2f7afdfca1023bad3baf
Reviewed-on: http://gerrit.openafs.org/11703
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

src/volser/dumpstuff.c

index e1754d1..63bf061 100644 (file)
@@ -265,12 +265,17 @@ ReadString(struct iod *iodp, char *to, int maxa)
     }
 }
 
-static void
-ReadByteString(struct iod *iodp, byte * to,
-              int size)
+static int
+ReadByteString(struct iod *iodp, byte * to, int size)
 {
-    while (size--)
-       *to++ = iod_getc(iodp);
+    int nbytes = 0;
+    int c;
+
+    while (size-- > 0 && (c = iod_getc(iodp)) != EOF) {
+       *to++ = c;
+       nbytes++;
+    }
+    return nbytes;
 }
 
 /*
@@ -1363,6 +1368,7 @@ ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
     FdHandle_t *fdP;
     Inode nearInode AFS_UNUSED;
     afs_int32 critical = 0;
+    int nbytes;
 
     tag = iod_getc(iodp);
     V_pref(vp, nearInode);
@@ -1428,8 +1434,13 @@ ReadVnodes(struct iod *iodp, Volume * vp, int incremental,
                    return VOLSERREAD_DUMPERROR;
                break;
            case 'A':
-               ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
+               nbytes = ReadByteString(iodp, (byte *) VVnodeDiskACL(vnode),
                               VAclDiskSize(vnode));
+               if (nbytes != VAclDiskSize(vnode)) {
+                   Log("ReadVnodes: could not read acl for vnode %lu in dump.\n",
+                        (unsigned long)vnodeNumber);
+                   return VOLSERREAD_DUMPERROR;
+               }
                if (acl_NtohACL(VVnodeDiskACL(vnode)) != 0) {
                    Log("ReadVnodes: invalid acl for vnode %lu in dump.\n",
                         (unsigned long)vnodeNumber);