aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2014-12-10 08:56:48 +0200
committerSergey Poznyakoff <gray@gnu.org>2014-12-10 08:56:48 +0200
commitbdd68868836f01ac766afa1a6c79a5f7d4287da6 (patch)
treed875e9fbf02575c9da52a2846ac00d09d5d3cefa
parent85dfe24a45c65a9f414769fe059b1c5a06a3b176 (diff)
downloadeclat-bdd68868836f01ac766afa1a6c79a5f7d4287da6.tar.gz
eclat-bdd68868836f01ac766afa1a6c79a5f7d4287da6.tar.bz2
Fix coredump when comparing non-existing nodes.
* lib/forlan.c (coerce_value): Handle NULL nodes. (values_equal): Handle NULL strings. (dump_expr): Handle EQ and NE. * lib/forlanlex.l: Fix distinction before negative numeric and identifier. * etc/describe-security-groups.fln: ipProtocol == "-1" means "all". * tests/Makefile.am: Add new tests. * tests/testsuite.at: Likewise. * tests/comp00.at: New file. * tests/comp01.at: New file. * tests/comp02.at: New file. * tests/comp03.at: New file. * tests/comp04.at: New file. * tests/tforlan.c (main): Optionally read XML from standard input.
-rw-r--r--etc/describe-security-groups.fln12
-rw-r--r--lib/forlan.c11
-rw-r--r--lib/forlanlex.l6
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/comp00.at60
-rw-r--r--tests/comp01.at60
-rw-r--r--tests/comp02.at50
-rw-r--r--tests/comp03.at42
-rw-r--r--tests/comp04.at42
-rw-r--r--tests/testsuite.at9
-rw-r--r--tests/tforlan.c16
11 files changed, 298 insertions, 15 deletions
diff --git a/etc/describe-security-groups.fln b/etc/describe-security-groups.fln
index 12a1379..4765c4a 100644
--- a/etc/describe-security-groups.fln
+++ b/etc/describe-security-groups.fln
@@ -25,7 +25,11 @@ if (.DescribeSecurityGroupsResponse.securityGroupInfo) {
print("Incoming:\n");
for (var in grp.ipPermissions.item) {
for (range in var.ipRanges.item) {
- print(var.ipProtocol,"\t",range.cidrIp,"\t",var.fromPort);
+ if (var.ipProtocol == "-1")
+ print("all");
+ else
+ print(var.ipProtocol);
+ print("\t",range.cidrIp,"\t",var.fromPort);
if (var.fromPort != var.toPort)
print("-",var.toPort);
print("\n");
@@ -42,7 +46,11 @@ if (.DescribeSecurityGroupsResponse.securityGroupInfo) {
print("Outgoing:\n");
for (var in grp.ipPermissionsEgress.item) {
for (range in var.ipRanges.item) {
- print(var.ipProtocol,"\t",range.cidrIp,"\t",var.fromPort);
+ if (var.ipProtocol == "-1")
+ print("all");
+ else
+ print(var.ipProtocol);
+ print("\t",range.cidrIp,"\t",var.fromPort);
if (var.fromPort != var.toPort)
print("-",var.toPort);
print("\n");
diff --git a/lib/forlan.c b/lib/forlan.c
index 53365ae..209d70d 100644
--- a/lib/forlan.c
+++ b/lib/forlan.c
@@ -189,7 +189,9 @@ coerce_value(forlan_eval_env_t env, struct forlan_value *val,
break;
case forlan_value_node:
- if (val->v.node->type == grecs_node_stmt) {
+ if (!val->v.node)
+ val->v.string = NULL;
+ else if (val->v.node->type == grecs_node_stmt) {
struct grecs_txtacc *acc = grecs_txtacc_create();
grecs_txtacc_format_value(val->v.node->v.value,
0, acc);
@@ -260,7 +262,10 @@ values_equal(forlan_eval_env_t env,
switch (t) {
case T_S:
- res = strcmp(a->v.string, b->v.string) == 0;
+ if (!a->v.string || !b->v.string)
+ res = a->v.string == b->v.string;
+ else
+ res = strcmp(a->v.string, b->v.string) == 0;
break;
case T_B:
res = !!a->v.num == !!b->v.num;
@@ -524,7 +529,7 @@ free_type_expr(union forlan_node *p)
void
dump_expr(FILE *fp, union forlan_node *p, int *num, int lev)
{
- static char *opstr[] = { "NODE", "AND", "OR", "NOT" };
+ static char *opstr[] = { "NODE", "AND", "OR", "NOT", "EQ", "NE" };
fprintf(fp, "%s\n", opstr[p->expr.opcode]);
forlan_dump_node(fp, p->expr.arg[0], num, lev + 1);
diff --git a/lib/forlanlex.l b/lib/forlanlex.l
index c5afdcd..d6fb335 100644
--- a/lib/forlanlex.l
+++ b/lib/forlanlex.l
@@ -59,7 +59,7 @@ static int yywrap(void);
%option nounput
WS [ \t\f][ \t\f]*
-IDC [a-zA-Z_0-9-]
+ID [a-zA-Z_][a-zA-Z_0-9-]*
%x COMMENT ML STR
%%
/* Comments */
@@ -70,7 +70,7 @@ IDC [a-zA-Z_0-9-]
<COMMENT>"*"+"/" BEGIN(INITIAL);
"//".* ;
/* Decimal numbers */
-[0-9][0-9]* { grecs_line_begin();
+-?[0-9][0-9]* { grecs_line_begin();
grecs_line_add(yytext, yyleng);
yylval.string = grecs_line_finish();
return STRING; }
@@ -88,7 +88,7 @@ continue return CONTINUE;
"||" return OR;
"==" return EQ;
"!=" return NE;
-{IDC}{IDC}* { grecs_line_begin();
+{ID} { grecs_line_begin();
grecs_line_add(yytext, yyleng);
yylval.string = grecs_line_finish();
return IDENT; }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b5d2cda..30e501b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -43,6 +43,11 @@ TESTSUITE_AT = \
allocate-address.at\
associate-address.at\
bidimap.at\
+ comp00.at\
+ comp01.at\
+ comp02.at\
+ comp03.at\
+ comp04.at\
create-snapshot.at\
decode.at\
delete-snapshot.at\
diff --git a/tests/comp00.at b/tests/comp00.at
new file mode 100644
index 0000000..21c0ec4
--- /dev/null
+++ b/tests/comp00.at
@@ -0,0 +1,60 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012-2014 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Node equal])
+AT_KEYWORDS([forlan compare comp comp00])
+
+AT_DATA([input],[
+if (.root.x == .root.y) print("PASS\n"); else print("FAIL\n");
+])
+
+AT_CHECK([tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>X</x>
+ <y>X</y>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>X</x>
+ <y>Y</y>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>X</x>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <empty/>
+</root>
+EOT],
+[0],
+[PASS
+FAIL
+FAIL
+PASS
+])
+
+AT_CLEANUP
diff --git a/tests/comp01.at b/tests/comp01.at
new file mode 100644
index 0000000..1913533
--- /dev/null
+++ b/tests/comp01.at
@@ -0,0 +1,60 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012-2014 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Node not equal])
+AT_KEYWORDS([forlan compare comp comp01])
+
+AT_DATA([input],[
+if (.root.x != .root.y) print("PASS\n"); else print("FAIL\n");
+])
+
+AT_CHECK([tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>X</x>
+ <y>X</y>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>X</x>
+ <y>Y</y>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>X</x>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <empty/>
+</root>
+EOT],
+[0],
+[FAIL
+PASS
+PASS
+FAIL
+])
+
+AT_CLEANUP
diff --git a/tests/comp02.at b/tests/comp02.at
new file mode 100644
index 0000000..0302c70
--- /dev/null
+++ b/tests/comp02.at
@@ -0,0 +1,50 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012-2014 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Node equals constant])
+AT_KEYWORDS([forlan compare comp comp02])
+
+AT_DATA([input],[
+if (.root.x == -1) print("PASS\n"); else print("FAIL\n");
+])
+
+AT_CHECK([tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>-1</x>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>1</x>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <empty/>
+</root>
+EOT],
+[0],
+[PASS
+FAIL
+FAIL
+])
+
+AT_CLEANUP
diff --git a/tests/comp03.at b/tests/comp03.at
new file mode 100644
index 0000000..892469f
--- /dev/null
+++ b/tests/comp03.at
@@ -0,0 +1,42 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012-2014 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Node defined])
+AT_KEYWORDS([forlan compare comp comp03])
+
+AT_DATA([input],[
+if (.root.x) print("PASS\n"); else print("FAIL\n");
+])
+
+AT_CHECK([tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>defined</x>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <y>1</y>
+</root>
+EOT],
+[0],
+[PASS
+FAIL
+])
+
+AT_CLEANUP
diff --git a/tests/comp04.at b/tests/comp04.at
new file mode 100644
index 0000000..b35d1c4
--- /dev/null
+++ b/tests/comp04.at
@@ -0,0 +1,42 @@
+# This file is part of Eclat -*- Autotest -*-
+# Copyright (C) 2012-2014 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Node not defined])
+AT_KEYWORDS([forlan compare comp comp04])
+
+AT_DATA([input],[
+if (!.root.x) print("PASS\n"); else print("FAIL\n");
+])
+
+AT_CHECK([tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <x>defined</x>
+</root>
+EOT
+
+tforlan -s input - <<EOT
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <y>1</y>
+</root>
+EOT],
+[0],
+[FAIL
+PASS
+])
+
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 5e4d2ee..9417283 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -40,7 +40,14 @@ m4_include([urlenc01.at])
AT_BANNER([XML Processing])
m4_include([xml01.at])
-AT_BANNER([Forlan])
+AT_BANNER([Forlan Node Comparisons])
+m4_include([comp00.at])
+m4_include([comp01.at])
+m4_include([comp02.at])
+m4_include([comp03.at])
+m4_include([comp04.at])
+
+AT_BANNER([Forlan Syntax])
m4_include([forlan01.at])
m4_include([exit.at])
m4_include([dump01.at])
diff --git a/tests/tforlan.c b/tests/tforlan.c
index 10010b5..219cad8 100644
--- a/tests/tforlan.c
+++ b/tests/tforlan.c
@@ -165,12 +165,16 @@ main(int argc, char **argv)
if (argv[1]) {
struct grecs_node *tree;
-
- fp = fopen(argv[1], "r");
- if (!fp)
- die(EX_UNAVAILABLE,
- "cannot open input file \"%s\": %s",
- argv[1], strerror(errno));
+
+ if (strcmp(argv[1], "-") == 0)
+ fp = stdin;
+ else {
+ fp = fopen(argv[1], "r");
+ if (!fp)
+ die(EX_UNAVAILABLE,
+ "cannot open input file \"%s\": %s",
+ argv[1], strerror(errno));
+ }
tree = parse_xml(fp);
fclose(fp);

Return to:

Send suggestions and report system problems to the System administrator.