pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14927: Unchecked SearchSysCache1() return value
3+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2017-11-28 cb03fa33ae 6448704496  Fix assorted syscache lookup sloppiness in partition-related code.
* BUG #14927: Unchecked SearchSysCache1() return value
@ 2017-11-27 09:01 bianpan2016@163.com
  2017-11-27 10:20 ` Re: BUG #14927: Unchecked SearchSysCache1() return value Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
  0 siblings, 1 reply; 3+ messages in thread

From: bianpan2016@163.com @ 2017-11-27 09:01 UTC (permalink / raw)
  To: pgsql-bugs; +Cc: bianpan2016@163.com

The following bug has been logged on the website:

Bug reference:      14927
Logged by:          Pan Bian
Email address:      bianpan2016@163.com
PostgreSQL version: 10.1
Operating system:   Linux
Description:        

File: postgresql-10.1/src/backend/catalog/heap.c
Function: heap_drop_with_catalog
Line: 1771

Function SearchSysCache1() may return a NULL pointer, but in
heap_drop_with_catalog(), its return value is not validated before it is
dereferenced. To avoid NULL dereference, it is better to check the return
value of SearchSysCache1() against NULL.

For your convenience, I paste related codes as follows:

1771     tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
1772     if (((Form_pg_class) GETSTRUCT(tuple))->relispartition)
1773     {
1774         parentOid = get_partition_parent(relid);
1775         LockRelationOid(parentOid, AccessExclusiveLock);
1776     }
1777 
1778     ReleaseSysCache(tuple);


Thank you!

Pan Bian




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #14927: Unchecked SearchSysCache1() return value
  2017-11-27 09:01 BUG #14927: Unchecked SearchSysCache1() return value bianpan2016@163.com
@ 2017-11-27 10:20 ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
  2017-11-27 11:34   ` Re: BUG #14927: Unchecked SearchSysCache1() return value PanBian <bianpan2016@163.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Amit Langote @ 2017-11-27 10:20 UTC (permalink / raw)
  To: bianpan2016@163.com; pgsql-bugs

On 2017/11/27 18:01, bianpan2016@163.com wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      14927
> Logged by:          Pan Bian
> Email address:      bianpan2016@163.com
> PostgreSQL version: 10.1
> Operating system:   Linux
> Description:        
> 
> File: postgresql-10.1/src/backend/catalog/heap.c
> Function: heap_drop_with_catalog
> Line: 1771
> 
> Function SearchSysCache1() may return a NULL pointer, but in
> heap_drop_with_catalog(), its return value is not validated before it is
> dereferenced. To avoid NULL dereference, it is better to check the return
> value of SearchSysCache1() against NULL.
> 
> For your convenience, I paste related codes as follows:
> 
> 1771     tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
> 1772     if (((Form_pg_class) GETSTRUCT(tuple))->relispartition)
> 1773     {
> 1774         parentOid = get_partition_parent(relid);
> 1775         LockRelationOid(parentOid, AccessExclusiveLock);
> 1776     }
> 1777 
> 1778     ReleaseSysCache(tuple);

Thanks for the report.  Attached a patch that adds a check that tuple is
valid before trying to dereference it.

Thanks,
Amit

Attachments:

syscache-check-tuple-heap.patch (text/plain, 1.2K) download diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 9e14880b99..f6c9283086 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -1772,6 +1772,8 @@ heap_drop_with_catalog(Oid relid) * shared-cache-inval notice that will make them update their index lists. */ tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for relation %u", relid); if (((Form_pg_class) GETSTRUCT(tuple))->relispartition) { parentOid = get_partition_parent(relid); diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index d19846d005..8cd6c65111 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -14111,6 +14111,9 @@ ATExecDetachPartition(Relation rel, RangeVar *name) classRel = heap_open(RelationRelationId, RowExclusiveLock); tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(RelationGetRelid(partRel))); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for relation %u", + RelationGetRelid(partRel)); Assert(((Form_pg_class) GETSTRUCT(tuple))->relispartition); (void) SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relpartbound,
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: BUG #14927: Unchecked SearchSysCache1() return value
  2017-11-27 09:01 BUG #14927: Unchecked SearchSysCache1() return value bianpan2016@163.com
  2017-11-27 10:20 ` Re: BUG #14927: Unchecked SearchSysCache1() return value Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
@ 2017-11-27 11:34   ` PanBian <bianpan2016@163.com>
  0 siblings, 0 replies; 3+ messages in thread

From: PanBian @ 2017-11-27 11:34 UTC (permalink / raw)
  To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; +Cc: pgsql-bugs

On Mon, Nov 27, 2017 at 07:20:51PM +0900, Amit Langote wrote:
> On 2017/11/27 18:01, bianpan2016@163.com wrote:
> > The following bug has been logged on the website:
> > 
> > Bug reference:      14927
> > Logged by:          Pan Bian
> > Email address:      bianpan2016@163.com
> > PostgreSQL version: 10.1
> > Operating system:   Linux
> > Description:        
> > 
> 
> Thanks for the report.  Attached a patch that adds a check that tuple is
> valid before trying to dereference it.
> 
> Thanks,
> Amit

Got it. These patches fixes the bug.

Thanks,
Pan Bian






^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2017-11-27 11:34 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 09:01 BUG #14927: Unchecked SearchSysCache1() return value bianpan2016@163.com
2017-11-27 10:20 ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
2017-11-27 11:34   ` PanBian <bianpan2016@163.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox