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

Commit8647c14

Browse files
committed
Fix buffer-overrun problem in pretty printer.
1 parent8970837 commit8647c14

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

‎src/backend/nodes/print.c

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.49 2001/10/25 05:49:31 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.50 2001/12/19 22:35:35 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -41,6 +41,7 @@ print(void *obj)
4141
s=nodeToString(obj);
4242
printf("%s\n",s);
4343
fflush(stdout);
44+
pfree(s);
4445
}
4546

4647
/*
@@ -49,59 +50,77 @@ print(void *obj)
4950
void
5051
pprint(void*obj)
5152
{
53+
#defineINDENTSTOP3
54+
#defineMAXINDENT60
55+
#defineLINELEN80
5256
char*s;
5357
inti;
54-
charline[80];
58+
charline[LINELEN];
5559
intindentLev;
60+
intindentDist;
5661
intj;
5762

5863
s=nodeToString(obj);
5964

60-
indentLev=0;
65+
indentLev=0;/* logical indent level */
66+
indentDist=0;/* physical indent distance */
6167
i=0;
6268
for (;;)
6369
{
64-
for (j=0;j<indentLev*3;j++)
70+
for (j=0;j<indentDist;j++)
6571
line[j]=' ';
66-
for (;j<75&&s[i]!='\0';i++,j++)
72+
for (;j<LINELEN-1&&s[i]!='\0';i++,j++)
6773
{
6874
line[j]=s[i];
6975
switch (line[j])
7076
{
7177
case'}':
72-
if (j!=indentLev*3)
78+
if (j!=indentDist)
7379
{
80+
/* print data before the } */
7481
line[j]='\0';
7582
printf("%s\n",line);
76-
line[indentLev*3]='\0';
77-
printf("%s}\n",line);
7883
}
79-
else
84+
/* print the } at indentDist */
85+
line[indentDist]='\0';
86+
printf("%s}\n",line);
87+
/* outdent */
88+
if (indentLev>0)
8089
{
81-
line[j]='\0';
82-
printf("%s}\n",line);
90+
indentLev--;
91+
indentDist=MIN(indentLev*INDENTSTOP,MAXINDENT);
8392
}
84-
indentLev--;
85-
j=indentLev*3-1;/* print the line before :
86-
* and resets */
93+
j=indentDist-1;
94+
/* j will equal indentDist on next loop iteration */
8795
break;
8896
case')':
97+
/* force line break after ')' */
8998
line[j+1]='\0';
9099
printf("%s\n",line);
91-
j=indentLev*3-1;
100+
j=indentDist-1;
92101
break;
93102
case'{':
103+
/* force line break before { */
104+
if (j!=indentDist)
105+
{
106+
line[j]='\0';
107+
printf("%s\n",line);
108+
}
109+
/* indent */
94110
indentLev++;
95-
/* !!! FALLS THROUGH */
111+
indentDist=MIN(indentLev*INDENTSTOP,MAXINDENT);
112+
for (j=0;j<indentDist;j++)
113+
line[j]=' ';
114+
line[j]=s[i];
115+
break;
96116
case':':
97-
if (j!=0)
117+
/* force line break before : */
118+
if (j!=indentDist)
98119
{
99120
line[j]='\0';
100121
printf("%s\n",line);
101-
/* print the line before : and resets */
102-
for (j=0;j<indentLev*3;j++)
103-
line[j]=' ';
104122
}
123+
j=indentDist;
105124
line[j]=s[i];
106125
break;
107126
}
@@ -114,7 +133,7 @@ pprint(void *obj)
114133
if (j!=0)
115134
printf("%s\n",line);
116135
fflush(stdout);
117-
return;
136+
pfree(s);
118137
}
119138

120139
/*
@@ -378,7 +397,7 @@ void
378397
print_plan_recursive(Plan*p,Query*parsetree,intindentLevel,char*label)
379398
{
380399
inti;
381-
charextraInfo[100];
400+
charextraInfo[NAMEDATALEN+100];
382401

383402
if (!p)
384403
return;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp