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

Arkadiusz Miskiewicz
2010-08-25T09:00:54Z

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@maven.pl>
> > ---
> >
> > 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)

#! /bin/bash
# FS QA Test No. xxx
#
# test to verify that correct project quota id is set
#
# creator
owner=arekm@maven.pl

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

_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` )
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
fi

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

mkdir $dir
touch $dir/below16bit
# 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)"
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)"
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"
fi

# success, all done
status=0
exit

--
Arkadiusz Miśkiewicz PLD/Linux Team
arekm / maven.pl http://ftp.pld-linux.org/