Skip to content

Commit 3967737

Browse files
committed
Add some assertions to view reloption macros
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
1 parent 604bd36 commit 3967737

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/include/utils/rel.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,19 @@ typedef struct ViewOptions
351351
* Returns whether the relation is security view, or not. Note multiple
352352
* eval of argument!
353353
*/
354-
#define RelationIsSecurityView(relation) \
355-
((relation)->rd_options ? \
356-
((ViewOptions *) (relation)->rd_options)->security_barrier : false)
354+
#define RelationIsSecurityView(relation) \
355+
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
356+
(relation)->rd_options ? \
357+
((ViewOptions *) (relation)->rd_options)->security_barrier : false)
357358

358359
/*
359360
* RelationHasCheckOption
360361
* Returns true if the relation is a view defined with either the local
361362
* or the cascaded check option. Note multiple eval of argument!
362363
*/
363364
#define RelationHasCheckOption(relation) \
364-
((relation)->rd_options && \
365+
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
366+
(relation)->rd_options && \
365367
((ViewOptions *) (relation)->rd_options)->check_option != \
366368
VIEW_OPTION_CHECK_OPTION_NOT_SET)
367369

@@ -371,7 +373,8 @@ typedef struct ViewOptions
371373
* option. Note multiple eval of argument!
372374
*/
373375
#define RelationHasLocalCheckOption(relation) \
374-
((relation)->rd_options && \
376+
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
377+
(relation)->rd_options && \
375378
((ViewOptions *) (relation)->rd_options)->check_option == \
376379
VIEW_OPTION_CHECK_OPTION_LOCAL)
377380

@@ -381,7 +384,8 @@ typedef struct ViewOptions
381384
* option. Note multiple eval of argument!
382385
*/
383386
#define RelationHasCascadedCheckOption(relation) \
384-
((relation)->rd_options && \
387+
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
388+
(relation)->rd_options && \
385389
((ViewOptions *) (relation)->rd_options)->check_option == \
386390
VIEW_OPTION_CHECK_OPTION_CASCADED)
387391

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy