Esempio n. 1
0
        private Type GetDataType(ExpressionNode node)
        {
            Type   nodeType = node.GetType();
            string typeName = null;

            if (nodeType == typeof(NameNode))
            {
                typeName = ((NameNode)node)._name;
            }
            if (nodeType == typeof(ConstNode))
            {
                typeName = ((ConstNode)node)._val.ToString();
            }

            if (typeName == null)
            {
                throw ExprException.ArgumentType(s_funcs[_info]._name, 2, typeof(Type));
            }

            Type dataType = Type.GetType(typeName);

            if (dataType == null)
            {
                throw ExprException.InvalidType(typeName);
            }

            // ReadXml might not be on the current call stack. So we'll use the TypeLimiter
            // that was captured when this FunctionNode instance was created.

            TypeLimiter.EnsureTypeIsAllowed(dataType, _capturedLimiter);

            return(dataType);
        }
Esempio n. 2
0
        internal FunctionNode(DataTable?table, string name) : base(table)
        {
            // Because FunctionNode instances are created eagerly but evaluated lazily,
            // we need to capture the deserialization scope here. The scope could be
            // null if no deserialization is in progress.

            _capturedLimiter = TypeLimiter.Capture();

            _name = name;
            for (int i = 0; i < s_funcs.Length; i++)
            {
                if (string.Equals(s_funcs[i]._name, name, StringComparison.OrdinalIgnoreCase))
                {
                    // we found the reserved word..
                    _info = i;
                    break;
                }
            }
            if (_info < 0)
            {
                throw ExprException.UndefinedFunction(_name);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Ensures the requested type is allowed by the rules of the active
        /// deserialization scope. If a captured scope is provided, we'll use
        /// that previously captured scope rather than the thread-static active
        /// scope.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// If <paramref name="type"/> is not allowed.
        /// </exception>
        public static void EnsureTypeIsAllowed(Type type, TypeLimiter capturedLimiter = null)
        {
            if (type is null)
            {
                return; // nothing to check
            }

            Scope capturedScope = capturedLimiter?.m_instanceScope ?? s_activeScope;

            if (capturedScope is null)
            {
                return; // we're not in a restricted scope
            }

            if (capturedScope.IsAllowedType(type))
            {
                return; // type was explicitly allowed
            }

            // We encountered a type that wasn't in the allow list.
            // Throw an exception to fail the current operation.

            throw ExceptionBuilder.TypeNotAllowed(type);
        }