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

Commitde52198

Browse files
committed
Fix latent crash in do_text_output_multiline().
do_text_output_multiline() would fail (typically with a null pointerdereference crash) if its input string did not end with a newline. Suchcases do not arise in our current sources; but it certainly could happenin future, or in extension code's usage of the function, so we should fixit. To fix, replace "eol += len" with "eol = text + len".While at it, make two cosmetic improvements: mark the input string const,and rename the argument from "text" to "txt" to dodge pgindent strangeness(since "text" is a typedef name).Even though this problem is only latent at present, it seems like a goodidea to back-patch the fix, since it's a very simple/safe patch and it'snot out of the realm of possibility that we might in future back-patchsomething that expects sane behavior from do_text_output_multiline().Per report from Hao Lee.Report: <CAGoxFiFPAGyPAJLcFxTB5cGhTW2yOVBDYeqDugYwV4dEd1L_Ag@mail.gmail.com>
1 parent7ac0342 commitde52198

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

‎src/backend/executor/execTuples.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,33 +1283,32 @@ do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
12831283
* Should only be used with a single-TEXT-attribute tupdesc.
12841284
*/
12851285
void
1286-
do_text_output_multiline(TupOutputState*tstate,char*text)
1286+
do_text_output_multiline(TupOutputState*tstate,constchar*txt)
12871287
{
12881288
Datumvalues[1];
12891289
boolisnull[1]= {false};
12901290

1291-
while (*text)
1291+
while (*txt)
12921292
{
1293-
char*eol;
1293+
constchar*eol;
12941294
intlen;
12951295

1296-
eol=strchr(text,'\n');
1296+
eol=strchr(txt,'\n');
12971297
if (eol)
12981298
{
1299-
len=eol-text;
1300-
1299+
len=eol-txt;
13011300
eol++;
13021301
}
13031302
else
13041303
{
1305-
len=strlen(text);
1306-
eol+=len;
1304+
len=strlen(txt);
1305+
eol=txt+len;
13071306
}
13081307

1309-
values[0]=PointerGetDatum(cstring_to_text_with_len(text,len));
1308+
values[0]=PointerGetDatum(cstring_to_text_with_len(txt,len));
13101309
do_tup_output(tstate,values,isnull);
13111310
pfree(DatumGetPointer(values[0]));
1312-
text=eol;
1311+
txt=eol;
13131312
}
13141313
}
13151314

‎src/include/executor/executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ typedef struct TupOutputState
276276
externTupOutputState*begin_tup_output_tupdesc(DestReceiver*dest,
277277
TupleDesctupdesc);
278278
externvoiddo_tup_output(TupOutputState*tstate,Datum*values,bool*isnull);
279-
externvoiddo_text_output_multiline(TupOutputState*tstate,char*text);
279+
externvoiddo_text_output_multiline(TupOutputState*tstate,constchar*txt);
280280
externvoidend_tup_output(TupOutputState*tstate);
281281

282282
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp