From: Shigeru Hanada Date: Fri, 1 Jul 2011 07:19:54 +0000 (+0900) Subject: Add filename check in file_fdw_validator. X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=e69f57cd033192850441c1a82f84ce4055e43074;p=users%2Fhanada%2Fpostgres.git Add filename check in file_fdw_validator. This fix is based on Albe's "Bug in SQL/MED?" patch. Error reporting in fileGetOptions() is also degrated to elog(). Per comment from Alvaro Herrera. --- diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index 466c015107..bf80568780 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -215,6 +215,17 @@ file_fdw_validator(PG_FUNCTION_ARGS) */ ProcessCopyOptions(NULL, true, other_options); + /* + * Filename is required for file_fdw foreign tables. We must validate it + * separately because ProcessCopyOptions() doesn't validate it. + * We don't care whether the value is empty or not, because COPY doesn't + * care that. + */ + if (catalog == ForeignTableRelationId && filename == NULL) + ereport(ERROR, + (errcode(ERRCODE_FDW_UNABLE_TO_CREATE_REPLY), + errmsg("filename is required for file_fdw foreign tables"))); + PG_RETURN_VOID(); } @@ -286,10 +297,15 @@ fileGetOptions(Oid foreigntableid, } prev = lc; } + + /* + * The requirement of filename option must have been checked by + * file_fdw_validator at every DDL. We check it here again just in case + * to avoid crash caused by unexpected catalog corruption. + */ if (*filename == NULL) - ereport(ERROR, - (errcode(ERRCODE_FDW_UNABLE_TO_CREATE_REPLY), - errmsg("filename is required for file_fdw foreign tables"))); + elog(ERROR, "filename is required for file_fdw foreign tables"); + *other_options = options; }