Browse code

core: trying to execute an undefined route will produce an error

Trying to call non-existing routes (via route("...")) will result
now in an error on startup (during fixups).
The old behaviour was to consider any non-existing routes as empty
(and do nothing).

Reported-by: Juha Heinanen jh tutpro com
Closes: FlySpray#51.

Andrei Pelinescu-Onciul authored on 25/03/2010 21:10:27
Showing 2 changed files
... ...
@@ -3043,14 +3043,14 @@ cmd:
3043 3043
 	| ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
3044 3044
 	| ERROR LPAREN error RPAREN { $$=0; yyerror("bad error argument"); }
3045 3045
 	| ROUTE LPAREN route_name RPAREN	{
3046
-						i_tmp=route_get(&main_rt, $3);
3047
-						if (i_tmp==-1){
3048
-							yyerror("internal error");
3049
-							YYABORT;
3050
-						}
3051
-						$$=mk_action(ROUTE_T, 1, NUMBER_ST,(void*)(long)i_tmp);
3052
-						set_cfg_pos($$);
3053
-										}
3046
+		if ($3) {
3047
+			$$ = mk_action(ROUTE_T, 1, STRING_ST, (void*)$3);
3048
+			set_cfg_pos($$);
3049
+		} else {
3050
+			$$ = 0;
3051
+			YYERROR;
3052
+		}
3053
+	}
3054 3054
 	| ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); }
3055 3055
 	| ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route argument"); }
3056 3056
 	| EXEC LPAREN STRING RPAREN	{ $$=mk_action(EXEC_T, 1, STRING_ST, $3); set_cfg_pos($$); }
... ...
@@ -727,7 +727,7 @@ int fix_actions(struct action* a)
727 727
 							LOG(L_ERR, "fix_actions: invalid expression "
728 728
 									"(%d,%d): type mismatch?",
729 729
 									rve->fpos.s_line, rve->fpos.s_col);
730
-						ret = E_UNSPEC;
730
+						ret = E_SCRIPT;
731 731
 						goto error;
732 732
 					}
733 733
 					/* it's not an error anymore to have non-int in an if,
... ...
@@ -810,14 +810,14 @@ int fix_actions(struct action* a)
810 810
 							LOG(L_ERR, "fix_actions: invalid expression "
811 811
 									"(%d,%d): type mismatch?",
812 812
 									rve->fpos.s_line, rve->fpos.s_col);
813
-						ret = E_UNSPEC;
813
+						ret = E_SCRIPT;
814 814
 						goto error;
815 815
 					}
816 816
 					if (rve_type!=RV_INT && rve_type!=RV_NONE){
817 817
 						LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
818 818
 								" bad type, integer expected\n",
819 819
 								rve->fpos.s_line, rve->fpos.s_col);
820
-						ret = E_UNSPEC;
820
+						ret = E_SCRIPT;
821 821
 						goto error;
822 822
 					}
823 823
 					if ((ret=fix_rval_expr(&t->val[0].u.data))<0)
... ...
@@ -854,14 +854,14 @@ int fix_actions(struct action* a)
854 854
 							LOG(L_ERR, "fix_actions: invalid expression "
855 855
 									"(%d,%d): type mismatch?",
856 856
 									rve->fpos.s_line, rve->fpos.s_col);
857
-						ret = E_UNSPEC;
857
+						ret = E_SCRIPT;
858 858
 						goto error;
859 859
 					}
860 860
 					if (rve_type!=RV_INT && rve_type!=RV_NONE){
861 861
 						LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
862 862
 								" bad type, integer expected\n",
863 863
 								rve->fpos.s_line, rve->fpos.s_col);
864
-						ret = E_UNSPEC;
864
+						ret = E_SCRIPT;
865 865
 						goto error;
866 866
 					}
867 867
 					if ((ret=fix_rval_expr(&t->val[0].u.data))<0)
... ...
@@ -1021,6 +1021,26 @@ int fix_actions(struct action* a)
1021 1021
 				t->val[0].u.str=s;
1022 1022
 				t->val[0].type=STR_ST;
1023 1023
 				break;
1024
+			case ROUTE_T:
1025
+				if (t->val[0].type == STRING_ST) {
1026
+					i=route_lookup(&main_rt, t->val[0].u.string);
1027
+					if (i < 0) {
1028
+						ERR("route \"%s\" not found at %s:%d\n", 
1029
+								t->val[0].u.string,
1030
+								(t->cfile)?t->cfile:"line", t->cline);
1031
+						ret = E_SCRIPT;
1032
+						goto error;
1033
+					}
1034
+					t->val[0].type = NUMBER_ST;
1035
+					pkg_free(t->val[0].u.string);
1036
+					t->val[0].u.number = i;
1037
+				} else if (t->val[0].type != NUMBER_ST) {
1038
+					BUG("invalid subtype %d for route()\n",
1039
+								t->val[0].type);
1040
+					ret = E_BUG;
1041
+					goto error;
1042
+				}
1043
+				break;
1024 1044
 			default:
1025 1045
 				/* no fixup required for the rest */
1026 1046
 				break;