Add some assertions to view reloption macros
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 1 Nov 2019 12:16:21 +0000 (13:16 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 1 Nov 2019 12:25:38 +0000 (13:25 +0100)
In these macros, the rd_options pointer is cast to ViewOption *.  Add
some assertions that the passed-in relation is actually a view before
doing that.

Author: Nikolay Shaplov <dhyan@nataraj.su>
Discussion: https://www.postgresql.org/message-id/flat/3634983.eHpMQ1mJnI@x200m

src/include/utils/rel.h

index a5cf804f9fc7b092071dbeb5b7bf6919afb180e4..8b8b237f0d828fd160a9cbf9e2175389d3c2e134 100644 (file)
@@ -351,9 +351,10 @@ typedef struct ViewOptions
  *     Returns whether the relation is security view, or not.  Note multiple
  *     eval of argument!
  */
-#define RelationIsSecurityView(relation)   \
-   ((relation)->rd_options ?               \
-    ((ViewOptions *) (relation)->rd_options)->security_barrier : false)
+#define RelationIsSecurityView(relation)                                   \
+   (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW),                \
+    (relation)->rd_options ?                                               \
+     ((ViewOptions *) (relation)->rd_options)->security_barrier : false)
 
 /*
  * RelationHasCheckOption
@@ -361,7 +362,8 @@ typedef struct ViewOptions
  *     or the cascaded check option.  Note multiple eval of argument!
  */
 #define RelationHasCheckOption(relation)                                   \
-   ((relation)->rd_options &&                                              \
+   (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW),                \
+    (relation)->rd_options &&                                              \
     ((ViewOptions *) (relation)->rd_options)->check_option !=              \
     VIEW_OPTION_CHECK_OPTION_NOT_SET)
 
@@ -371,7 +373,8 @@ typedef struct ViewOptions
  *     option.  Note multiple eval of argument!
  */
 #define RelationHasLocalCheckOption(relation)                              \
-   ((relation)->rd_options &&                                              \
+   (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW),                \
+    (relation)->rd_options &&                                              \
     ((ViewOptions *) (relation)->rd_options)->check_option ==              \
     VIEW_OPTION_CHECK_OPTION_LOCAL)
 
@@ -381,7 +384,8 @@ typedef struct ViewOptions
  *     option.  Note multiple eval of argument!
  */
 #define RelationHasCascadedCheckOption(relation)                           \
-   ((relation)->rd_options &&                                              \
+   (AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW),                \
+    (relation)->rd_options &&                                              \
     ((ViewOptions *) (relation)->rd_options)->check_option ==              \
      VIEW_OPTION_CHECK_OPTION_CASCADED)