xfs
[Top] [All Lists]

Re: [PATCH] Validate string -> number conversion.

To: Arkadiusz Miskiewicz <arekm@xxxxxxxx>
Subject: Re: [PATCH] Validate string -> number conversion.
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Thu, 26 Aug 2010 18:42:49 +1000
Cc: xfs@xxxxxxxxxxx
In-reply-to: <201008251101.27106.arekm@xxxxxxxx>
References: <1282724556-19456-1-git-send-email-arekm@xxxxxxxx> <201008251045.54899.arekm@xxxxxxxx> <201008251101.27106.arekm@xxxxxxxx>
User-agent: Mutt/1.5.20 (2009-06-14)
On Wed, Aug 25, 2010 at 11:01:26AM +0200, Arkadiusz Miskiewicz wrote:
> On Wednesday 25 of August 2010, Arkadiusz Miskiewicz wrote:
> > On Wednesday 25 of August 2010, Arkadiusz Miśkiewicz wrote:
> > > Make sure that numbers passed as string will fit into proper
> > > types when doing string->uid_t/gid_t/prid_t conversion.
> > > 
> > > Signed-off-by: Arkadiusz Miśkiewicz <arekm@xxxxxxxx>
> > > ---
> > > 
> > >  libxcmd/input.c |   18 +++++++++++++++---
> > >  quota/project.c |    2 +-
> > >  2 files changed, 16 insertions(+), 4 deletions(-)
> > 
> > On the kernel side something like below is needed (compile tested only).
> > The true fix is to extend on disk di_projid to 32bit (there is room for
> > that).
> 
> template of test suite for this problem
> (likely needs some small amount of work)

Great - thanks for doing this. A couple of comments, though.

First, I'm assuming that no output should occur if everything
succeeds?  If so, we normally put an:

echo "Silence is golden"

in the test to document that we expect no other output.

> 
> #! /bin/bash
> # FS QA Test No. xxx
> #
> # test to verify that correct project quota id is set
> #
> # creator

Can you add the GPL text and copyright here so the license is clear
and we know where it came from?

> owner=arekm@xxxxxxxx
> 
> seq=`basename $0`
> echo "QA output created by $seq"
> 
> here=`pwd`
> tmp=/tmp/$$
> status=1      # failure is the default!
> 
> # get standard environment, filters and checks
> . ./common.rc
> . ./common.filter
> . ./common.quota
> 
> _cleanup()
> {
>       cd /
>       umount $SCRATCH_MNT 2>/dev/null
>       rm -f $tmp.*
> }
> #trap "_cleanup; exit \$status" 0 1 2 3 15
> 
> 
> # real QA test starts here
> _supported_fs xfs
> _supported_os Linux IRIX

I'm not sure any will ever validate this on Irix, so maybe that
should be left out?

> 
> _require_xfs_quota
> 
> dir=$SCRATCH_MNT/project
> 
> _require_scratch
> _scratch_mkfs_xfs >/dev/null 2>&1
> 
> #if pquota's already in mount options then we dont need to enable
> 
> # we can't run with group quotas
> if ( `echo $MOUNT_OPTIONS | grep -q gquota` || `echo $MOUNT_OPTIONS | grep -q 
> grpquota` )

if ( `echo $MOUNT_OPTIONS | egrep -q g??quota` )

> then
>     _notrun "Can't run with group quotas enabled"
> fi
> EXTRA_MOUNT_OPTIONS="-o pquota"
> 
> if ! _scratch_mount "$EXTRA_MOUNT_OPTIONS" >$tmp.out 2>&1
> then
>     cat $tmp.out
>     echo "!!! mount failed"
>     exit

        _fail "!!! failed to mount

> fi
> 
> src/feature -p $SCRATCH_DEV
> [ $? -ne 0 ] && _notrun "Installed kernel does not support project quotas"

This test should probably be first.

> mkdir $dir
> touch $dir/below16bit

status=0

> # below 16bit value
> xfs_quota -x -c "project -s -p $dir/below16bit 3422" $SCRATCH_DEV
> projid=$($XFS_IO_PROG -r -c "lsproj" $dir/below16bit)
> if [ "projid = 3422" != "$projid" ]; then
>       echo "FAIL: returned projid value ($projid) doesn't match set one 
> (3422)"

        status=1

> fi
> 
> # over 16bit value
> touch $dir/over16bit
> xfs_quota -x -c "project -s -p $dir/over16bit 108545" $SCRATCH_DEV
> projid=$($XFS_IO_PROG -r -c "lsproj" $dir)
> if [ "projid = 108545" != "$projid" ]; then
>       echo "FAIL: returned projid value ($projid) doesn't match set one 
> (108545)"

        status=1

> fi
> 
> # over 32bit value, should fail
> touch $dir/over32bit
> if ! xfs_quota -x -c "project -s -p $dir/over32bit 5344967296" $SCRATCH_DEV; 
> then
>       echo "FAIL: setting over 32bit projid succeeded while it should fail"

        status=1

> fi
> 
> # success, all done
> status=0

Remove these two lines.

> exit


Cheers,

Dave.
-- 
Dave Chinner
david@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>