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

Commit9d91cd8

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 parent7fc5064 commit9d91cd8

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
@@ -1325,33 +1325,32 @@ do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
13251325
* Should only be used with a single-TEXT-attribute tupdesc.
13261326
*/
13271327
void
1328-
do_text_output_multiline(TupOutputState*tstate,char*text)
1328+
do_text_output_multiline(TupOutputState*tstate,constchar*txt)
13291329
{
13301330
Datumvalues[1];
13311331
boolisnull[1]= {false};
13321332

1333-
while (*text)
1333+
while (*txt)
13341334
{
1335-
char*eol;
1335+
constchar*eol;
13361336
intlen;
13371337

1338-
eol=strchr(text,'\n');
1338+
eol=strchr(txt,'\n');
13391339
if (eol)
13401340
{
1341-
len=eol-text;
1342-
1341+
len=eol-txt;
13431342
eol++;
13441343
}
13451344
else
13461345
{
1347-
len=strlen(text);
1348-
eol+=len;
1346+
len=strlen(txt);
1347+
eol=txt+len;
13491348
}
13501349

1351-
values[0]=PointerGetDatum(cstring_to_text_with_len(text,len));
1350+
values[0]=PointerGetDatum(cstring_to_text_with_len(txt,len));
13521351
do_tup_output(tstate,values,isnull);
13531352
pfree(DatumGetPointer(values[0]));
1354-
text=eol;
1353+
txt=eol;
13551354
}
13561355
}
13571356

‎src/include/executor/executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ typedef struct TupOutputState
283283
externTupOutputState*begin_tup_output_tupdesc(DestReceiver*dest,
284284
TupleDesctupdesc);
285285
externvoiddo_tup_output(TupOutputState*tstate,Datum*values,bool*isnull);
286-
externvoiddo_text_output_multiline(TupOutputState*tstate,char*text);
286+
externvoiddo_text_output_multiline(TupOutputState*tstate,constchar*txt);
287287
externvoidend_tup_output(TupOutputState*tstate);
288288

289289
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp