Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4700393

Browse files
committed
Remove fixed-size buffers in rule storage routine.
1 parent918d9de commit4700393

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

‎src/backend/rewrite/rewriteDefine.c

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.36 1999/09/18 19:07:18 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.37 1999/10/21 01:46:24 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -16,6 +16,7 @@
1616

1717
#include"access/heapam.h"
1818
#include"catalog/pg_rewrite.h"
19+
#include"lib/stringinfo.h"
1920
#include"parser/parse_relation.h"
2021
#include"rewrite/rewriteDefine.h"
2122
#include"rewrite/rewriteSupport.h"
@@ -24,23 +25,32 @@
2425

2526
OidLastOidProcessed=InvalidOid;
2627

28+
29+
/*
30+
* Convert given string to a suitably quoted string constant,
31+
* and append it to the StringInfo buffer.
32+
* XXX Any MULTIBYTE considerations here?
33+
*/
2734
staticvoid
28-
strcpyq(char*dest,char*source)
35+
quoteString(StringInfobuf,char*source)
2936
{
30-
char*current=source,
31-
*destp=dest;
37+
char*current;
3238

39+
appendStringInfoChar(buf,'\'');
3340
for (current=source;*current;current++)
3441
{
35-
if (*current=='\"')
42+
charch=*current;
43+
if (ch=='\''||ch=='\\')
3644
{
37-
*destp='\\';
38-
destp++;
45+
appendStringInfoChar(buf,'\\');
46+
appendStringInfoChar(buf,ch);
3947
}
40-
*destp=*current;
41-
destp++;
48+
elseif (ch >=0&&ch<' ')
49+
appendStringInfo(buf,"\\%03o", (int)ch);
50+
else
51+
appendStringInfoChar(buf,ch);
4252
}
43-
*destp='\0';
53+
appendStringInfoChar(buf,'\'');
4454
}
4555

4656
/*
@@ -68,15 +78,11 @@ InsertRule(char *rulname,
6878
boolevinstead,
6979
char*actiontree)
7080
{
71-
staticcharrulebuf[MaxAttrSize];
72-
staticcharactionbuf[MaxAttrSize];
73-
staticcharqualbuf[MaxAttrSize];
74-
Oideventrel_oid=InvalidOid;
75-
AttrNumberevslot_index=InvalidAttrNumber;
76-
Relationeventrel=NULL;
81+
StringInfoDatarulebuf;
82+
Relationeventrel;
83+
Oideventrel_oid;
84+
AttrNumberevslot_index;
7785
char*is_instead="f";
78-
externvoideval_as_new_xact();
79-
char*template;
8086

8187
eventrel=heap_openr(evobj,AccessShareLock);
8288
eventrel_oid=RelationGetRelid(eventrel);
@@ -87,7 +93,7 @@ InsertRule(char *rulname,
8793
if (evslot==NULL)
8894
evslot_index=-1;
8995
else
90-
evslot_index=attnameAttNum(eventrel,(char*)evslot);
96+
evslot_index=attnameAttNum(eventrel,evslot);
9197
heap_close(eventrel,AccessShareLock);
9298

9399
if (evinstead)
@@ -99,22 +105,21 @@ InsertRule(char *rulname,
99105
if (IsDefinedRewriteRule(rulname))
100106
elog(ERROR,"Attempt to insert rule '%s' failed: already exists",
101107
rulname);
102-
strcpyq(actionbuf,actiontree);
103-
strcpyq(qualbuf,evqual);
104-
105-
template="INSERT INTO pg_rewrite \
106-
(rulename, ev_type, ev_class, ev_attr, ev_action, ev_qual, is_instead) VALUES \
107-
('%s', %d::char, %u::oid, %d::int2, '%s'::text, '%s'::text, \
108-
'%s'::bool);";
109-
if (MAXALIGN(sizeof(FormData_pg_rewrite))+
110-
MAXALIGN(strlen(actionbuf))+
111-
MAXALIGN(strlen(qualbuf))>MaxAttrSize)
112-
elog(ERROR,"DefineQueryRewrite: rule plan string too big.");
113-
sprintf(rulebuf,template,
114-
rulname,evtype,eventrel_oid,evslot_index,actionbuf,
115-
qualbuf,is_instead);
116-
117-
pg_exec_query_acl_override(rulebuf);
108+
109+
initStringInfo(&rulebuf);
110+
appendStringInfo(&rulebuf,
111+
"INSERT INTO pg_rewrite (rulename, ev_type, ev_class, ev_attr, ev_action, ev_qual, is_instead) VALUES (");
112+
quoteString(&rulebuf,rulname);
113+
appendStringInfo(&rulebuf,", %d::char, %u::oid, %d::int2, ",
114+
evtype,eventrel_oid,evslot_index);
115+
quoteString(&rulebuf,actiontree);
116+
appendStringInfo(&rulebuf,"::text, ");
117+
quoteString(&rulebuf,evqual);
118+
appendStringInfo(&rulebuf,"::text, '%s'::bool);",
119+
is_instead);
120+
121+
pg_exec_query_acl_override(rulebuf.data);
122+
pfree(rulebuf.data);
118123

119124
returnLastOidProcessed;
120125
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp