提交 720237b6 编写于 作者: D Daniel Gustafsson

Check for overflow in filename generation

The filename is defined as MAXPGPATH which can overflow on macOS
when 64 bit inodes are used,  since the dirent struct can hold 1023
character dir entries (Linux has a dirent64 struct instead of over-
loading dirent). Guard against possible overflow and ereport a
WARNING in case it happens. While perhaps not technically required
on other platforms it's good practice to check for overflow either
way so avoid ifdefing for only macOS.
上级 f63960ba
......@@ -896,10 +896,11 @@ ErrorLogDelete(Oid databaseId, Oid relationId)
if (!OidIsValid(relationId))
{
DIR *dir;
struct dirent *de;
char *dirpath = ErrorLogDir;
char prefix[MAXPGPATH];
DIR *dir;
struct dirent *de;
char *dirpath = ErrorLogDir;
char prefix[MAXPGPATH];
int len;
if (OidIsValid(databaseId))
snprintf(prefix, sizeof(prefix), "%u_", databaseId);
......@@ -924,8 +925,16 @@ ErrorLogDelete(Oid databaseId, Oid relationId)
*/
if (!OidIsValid(databaseId))
{
len = snprintf(filename, MAXPGPATH, "%s/%s", dirpath, de->d_name);
if (len >= (MAXPGPATH - 1))
{
ereport(WARNING,
(errcode(ERRCODE_GP_INTERNAL_ERROR),
(errmsg("log filename truncation on \"%s\", unable to delete error log",
de->d_name))));
continue;
}
LWLockAcquire(ErrorLogLock, LW_EXCLUSIVE);
sprintf(filename, "%s/%s", dirpath, de->d_name);
unlink(filename);
LWLockRelease(ErrorLogLock);
continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册