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

Commit4bf70c0

Browse files
committed
Prevent using strncpy with src == dest in TupleDescInitEntry.
The C and POSIX standards state that strncpy's behavior is undefined whensource and destination areas overlap. While it remains dubious whether anyimplementations really misbehave when the pointers are exactly equal, someplatforms are now starting to force the issue by complaining when anundefined call occurs. (In particular OS X 10.9 has been seen to dump corehere, though the exact set of circumstances needed to trigger that remainelusive. Similar behavior can be expected to be optional on Linux andother platforms in the near future.) So tweak the code to explicitly donothing when nothing need be done.Back-patch to all active branches. In HEAD, this also lets us get rid ofan exception in valgrind.supp.Per discussion of a report from Matthias Schmitt.
1 parente78ed04 commit4bf70c0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

‎src/backend/access/common/tupdesc.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,12 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
430430
*This function initializes a single attribute structure in
431431
*a previously allocated tuple descriptor.
432432
*
433+
* If attributeName is NULL, the attname field is set to an empty string
434+
* (this is for cases where we don't know or need a name for the field).
435+
* Also, some callers use this function to change the datatype-related fields
436+
* in an existing tupdesc; they pass attributeName = NameStr(att->attname)
437+
* to indicate that the attname field shouldn't be modified.
438+
*
433439
* Note that attcollation is set to the default for the specified datatype.
434440
* If a nondefault collation is needed, insert it afterwards using
435441
* TupleDescInitEntryCollation.
@@ -463,12 +469,12 @@ TupleDescInitEntry(TupleDesc desc,
463469
/*
464470
* Note: attributeName can be NULL, because the planner doesn't always
465471
* fill in valid resname values in targetlists, particularly for resjunk
466-
* attributes.
472+
* attributes. Also, do nothing if caller wants to re-use the old attname.
467473
*/
468-
if (attributeName!=NULL)
469-
namestrcpy(&(att->attname),attributeName);
470-
else
474+
if (attributeName==NULL)
471475
MemSet(NameStr(att->attname),0,NAMEDATALEN);
476+
elseif (attributeName!=NameStr(att->attname))
477+
namestrcpy(&(att->attname),attributeName);
472478

473479
att->attstattarget=-1;
474480
att->attcacheoff=-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp