Check that there is only one of read, write, create_expire

This commit is contained in:
Johanna Amann 2016-03-18 12:34:26 -07:00
parent 8de0804712
commit cfffb6e634
5 changed files with 36 additions and 0 deletions

View file

@ -375,12 +375,33 @@ void Attributes::CheckAttr(Attr* a)
case ATTR_EXPIRE_READ: case ATTR_EXPIRE_READ:
case ATTR_EXPIRE_WRITE: case ATTR_EXPIRE_WRITE:
case ATTR_EXPIRE_CREATE: case ATTR_EXPIRE_CREATE:
{
if ( type->Tag() != TYPE_TABLE ) if ( type->Tag() != TYPE_TABLE )
{ {
Error("expiration only applicable to tables"); Error("expiration only applicable to tables");
break; break;
} }
int num_expires = 0;
if ( attrs )
{
loop_over_list(*attrs, i)
{
Attr* a = (*attrs)[i];
if ( a->Tag() == ATTR_EXPIRE_READ ||
a->Tag() == ATTR_EXPIRE_WRITE ||
a->Tag() == ATTR_EXPIRE_CREATE )
num_expires++;
}
}
if ( num_expires > 1 )
{
Error("set/table can only have one of &read_expire, &write_expire, &create_expire");
break;
}
}
#if 0 #if 0
//### not easy to test this w/o knowing the ID. //### not easy to test this w/o knowing the ID.
if ( ! IsGlobal() ) if ( ! IsGlobal() )

View file

@ -0,0 +1 @@
error in /Users/johanna/bro/master/testing/btest/.tmp/language.expire_multiple-2/expire_multiple.test, line 2: set/table can only have one of &read_expire, &write_expire, &create_expire (&write_expire=1.0 sec, &create_expire=3.0 secs)

View file

@ -0,0 +1 @@
error in /Users/johanna/bro/master/testing/btest/.tmp/language.expire_multiple-3/expire_multiple.test, line 2: set/table can only have one of &read_expire, &write_expire, &create_expire (&write_expire=1.0 sec, &read_expire=3.0 secs)

View file

@ -0,0 +1 @@
error in /Users/johanna/bro/master/testing/btest/.tmp/language.expire_multiple/expire_multiple.test, line 4: set/table can only have one of &read_expire, &write_expire, &create_expire (&create_expire=1.0 sec, &read_expire=1.0 sec)

View file

@ -0,0 +1,12 @@
# @TEST-EXEC-FAIL: bro -b %INPUT >output 2>&1
# @TEST-EXEC: btest-diff output
global s: set[string] &create_expire=1secs &read_expire=1secs;
# @TEST-START-NEXT:
global s: set[string] &write_expire=1secs &create_expire=3secs;
# @TEST-START-NEXT:
global s: set[string] &write_expire=1secs &read_expire=3secs;