From: | Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp> |
---|---|
To: | bianpan2016(at)163(dot)com, pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #14929: Unchecked AllocateDir() return value in restoreTwoPhaseData() |
Date: | 2017-11-27 10:35:35 |
Message-ID: | 728f1223-9a35-56cb-8854-afb84849c2cc@lab.ntt.co.jp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On 2017/11/27 18:31, bianpan2016(at)163(dot)com wrote:
> The following bug has been logged on the website:
>
> Bug reference: 14929
> Logged by: Pan Bian
> Email address: bianpan2016(at)163(dot)com
> PostgreSQL version: 10.1
> Operating system: Linux
> Description:
>
> File: src/backend/access/transam/twophase.c
> Function: restoreTwoPhaseData
> Line: 1738
>
> AllocateDir() will return a NULL pointer if it fails to open the specified
> directory. However, in function restoreTwoPhaseData(), its return value is
> not checked. This may result in a NULL pointer dereference when trying to
> free it (see line 1759).
>
> For your convenience, I copy and paste related codes as follows:
>
> 1732 void
> 1733 restoreTwoPhaseData(void)
> 1734 {
> 1735 DIR *cldir;
> 1736 struct dirent *clde;
> 1737
> 1738 cldir = AllocateDir(TWOPHASE_DIR);
> 1739 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
> 1740 while ((clde = ReadDir(cldir, TWOPHASE_DIR)) != NULL)
> 1741 {
> ...
> 1758 LWLockRelease(TwoPhaseStateLock);
> 1759 FreeDir(cldir);
> 1760 }
Thanks for the report.
It seems like a good idea to check cldir for NULL before freeing. Please
find attached a patch to implement the same.
Thanks,
Amit
Attachment | Content-Type | Size |
---|---|---|
AllocateDir-result-could-be-NULL.patch | text/plain | 367 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2017-11-27 10:53:30 | Re: BUG #14929: Unchecked AllocateDir() return value in restoreTwoPhaseData() |
Previous Message | Amit Langote | 2017-11-27 10:21:32 | Re: BUG #14928: Unchecked SearchSysCacheCopy1() return value |