/** * Checks whatever extending a file from this offset with to a given length * will overflow NFS4_UINT64_MAX. * * @see #checkOverflow(long, java.lang.String) * @param length to verify * @param msg included into exception * @throws InvalException if offset + length will overflow */ public void checkOverflow(int length, String msg) throws InvalException { checkOverflow((long)length, msg); }
/** * Checks whatever extending a file from this offset with to a given length * will overflow NFS4_UINT64_MAX. * * @see #checkOverflow(long, java.lang.String) * @param length to verify * @param msg included into exception * @throws InvalException if offset + length will overflow */ public void checkOverflow(length4 length, String msg) throws InvalException { checkOverflow(length.value, msg); }
@Override public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNFSException, IOException { final COMMIT4res res = result.opcommit; Inode inode = context.currentInode(); _args.opcommit.offset.checkOverflow(_args.opcommit.count.value, "offset + length overflow"); context.getFs().commit(inode, _args.opcommit.offset.value, _args.opcommit.count.value); res.resok4 = new COMMIT4resok(); res.resok4.writeverf = context.getRebootVerifier(); result.opcommit.status = nfsstat.NFS_OK; } }
@Test public void shouldSuccessSignedLongOverflow() throws Exception { offset4 offset = new offset4(Long.MAX_VALUE); length4 length = new length4(5); offset.checkOverflow(length, null); } }
@Test public void shouldSucceedIfSumNotOverflow() throws Exception { offset4 offset = new offset4(5); length4 length = new length4(Long.MAX_VALUE - 10); offset.checkOverflow(length, null); }
@Test(expected = InvalException.class) public void shouldfailIfSumOverflow() throws Exception { offset4 offset = new offset4(UnsignedLong.MAX_VALUE.longValue()); length4 length = new length4(5); offset.checkOverflow(length, null); }
_args.opwrite.offset.checkOverflow(_args.opwrite.data.remaining(), "offset + length overflow");
_args.opwrite.offset.checkOverflow(_args.opwrite.data.remaining(), "offset + length overflow");
@Override public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNFSException, IOException, OncRpcException { // FIXME: sync the data _args.opcommit.offset.checkOverflow(_args.opcommit.count.value, "offset + length overflow"); final COMMIT4res res = result.opcommit; if (context.getFs() != null) { Inode inode = context.currentInode(); Stat stat = context.getFs().getattr(inode); if (stat.type() == Stat.Type.DIRECTORY) { throw new IsDirException("Invalid can't commit a directory"); } if (stat.type() != Stat.Type.REGULAR) { throw new InvalException("Invalid object type"); } FileChannel out = _fsCache.get(inode); Stat newStat = new Stat(); newStat.setSize(out.size()); context.getFs().setattr(context.currentInode(), newStat); } res.status = nfsstat.NFS_OK; res.resok4 = new COMMIT4resok(); res.resok4.writeverf = context.getRebootVerifier(); } }
_args.oplayoutget.loga_offset.checkOverflow(_args.oplayoutget.loga_length, "offset + length overflow"); _args.oplayoutget.loga_offset.checkOverflow(_args.oplayoutget.loga_minlength, "offset + minlength overflow");
_args.oplocku.offset.checkOverflow(_args.oplocku.length, "offset + len overflow");
_args.oplock.offset.checkOverflow(_args.oplock.length, "offset + len overflow");