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

Commit53960e7

Browse files
committed
Fix off-by-one loop count in MapArrayTypeName, and get rid of static array.
MapArrayTypeName would copy up to NAMEDATALEN-1 bytes of the base typename, which of course is wrong: after prepending '_' there is only room forNAMEDATALEN-2 bytes. Aside from being the wrong result, this case wouldlead to overrunning the statically allocated work buffer. This would be asecurity bug if the function were ever used outside bootstrap mode, but itisn't, at least not in any currently supported branches.Aside from fixing the off-by-one loop logic, this patch gets rid of thestatic work buffer by having MapArrayTypeName pstrdup its result; the solecaller was already doing that, so this just requires moving the pstrdupcall. This saves a few bytes but mainly it makes the API a lot cleaner.Back-patch on the off chance that there is some third-party code usingMapArrayTypeName with less-secure input. Pushing pstrdup into the functionshould not cause any serious problems for such hypothetical code; at worstthere might be a short term memory leak.Per Coverity scanning.
1 parent3b750ec commit53960e7

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

‎src/backend/bootstrap/bootscanner.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ insert{ return(INSERT_TUPLE); }
111111
"toast"{return(XTOAST); }
112112

113113
{arrayid}{
114-
yylval.str =pstrdup(MapArrayTypeName(yytext));
114+
yylval.str =MapArrayTypeName(yytext);
115115
return(ID);
116116
}
117117
{id}{

‎src/backend/bootstrap/bootstrap.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,38 +1037,33 @@ AllocateAttribute(void)
10371037
returnattribute;
10381038
}
10391039

1040-
/* ----------------
1040+
/*
10411041
*MapArrayTypeName
1042-
* XXX arrays of "basetype" are always "_basetype".
1043-
* this is an evil hack inherited from rel. 3.1.
1044-
* XXX array dimension is thrown away because we
1045-
* don't support fixed-dimension arrays. again,
1046-
* sickness from 3.1.
10471042
*
1048-
* the string passed in must have a '[' character in it
1043+
* Given a type name, produce the corresponding array type name by prepending
1044+
* '_' and truncating as needed to fit in NAMEDATALEN-1 bytes. This is only
1045+
* used in bootstrap mode, so we can get away with assuming that the input is
1046+
* ASCII and we don't need multibyte-aware truncation.
10491047
*
1050-
*thestringreturned is a pointer to static storage and should NOT
1051-
* be freed by the CALLER.
1052-
*----------------
1048+
*The givenstringnormally ends with '[]' or '[digits]'; we discard that.
1049+
*
1050+
*The result is a palloc'd string.
10531051
*/
10541052
char*
1055-
MapArrayTypeName(char*s)
1053+
MapArrayTypeName(constchar*s)
10561054
{
10571055
inti,
10581056
j;
1059-
staticcharnewStr[NAMEDATALEN];/* array type names < NAMEDATALEN long */
1057+
charnewStr[NAMEDATALEN];
10601058

1061-
if (s==NULL||s[0]=='\0')
1062-
returns;
1063-
1064-
j=1;
10651059
newStr[0]='_';
1066-
for (i=0;i<NAMEDATALEN-1&&s[i]!='[';i++,j++)
1060+
j=1;
1061+
for (i=0;i<NAMEDATALEN-2&&s[i]!='[';i++,j++)
10671062
newStr[j]=s[i];
10681063

10691064
newStr[j]='\0';
10701065

1071-
returnnewStr;
1066+
returnpstrdup(newStr);
10721067
}
10731068

10741069

‎src/include/bootstrap/bootstrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extern void InsertOneTuple(Oid objectid);
4040
externvoidInsertOneValue(char*value,inti);
4141
externvoidInsertOneNull(inti);
4242

43-
externchar*MapArrayTypeName(char*s);
43+
externchar*MapArrayTypeName(constchar*s);
4444

4545
externvoidindex_register(Oidheap,Oidind,IndexInfo*indexInfo);
4646
externvoidbuild_indices(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp