From ed52d65fe98549e13023e0a8997da479b626085a Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Fri, 30 Jan 2015 12:20:10 -0500 Subject: [PATCH] volser: detect eof in dump stream while reading acl 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 Tested-by: BuildBot --- src/volser/dumpstuff.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/volser/dumpstuff.c b/src/volser/dumpstuff.c index e1754d13f..63bf061c4 100644 --- a/src/volser/dumpstuff.c +++ b/src/volser/dumpstuff.c @@ -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); -- 2.39.5