Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions contrib/uuid-ossp/uuid-ossp.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,15 @@ Datum
ora_sys_guid(PG_FUNCTION_ARGS)
{
bytea *result;
#ifdef HAVE_UUID_OSSP
uuid_t *uuid;
uuid_rc_t rc;
#endif

result = (bytea *)palloc(VARHDRSZ + SYS_GUID_LENGTH);
SET_VARSIZE(result, VARHDRSZ + SYS_GUID_LENGTH);

#ifdef HAVE_UUID_OSSP
uuid_t *uuid;
uuid_rc_t rc;
uuid = get_cached_uuid_t(0);
rc = uuid_make(uuid, UUID_MAKE_V4, NULL, NULL);
if (rc != UUID_RC_OK) {
Expand All @@ -589,4 +592,4 @@ ora_sys_guid(PG_FUNCTION_ARGS)
memcpy(VARDATA(result), byte_array, SYS_GUID_LENGTH);
#endif
PG_RETURN_BYTEA_P(result);
}
}
25 changes: 21 additions & 4 deletions src/backend/catalog/genbki.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1118,10 +1118,27 @@ sub lookup_oids
push @lookupoids, $lookupname;
if ($lookupname eq '-' or $lookupname eq '0')
{
warn sprintf
"invalid zero OID reference in %s.dat field %s line %s\n",
$catname, $attname, $bki_values->{line_number}
if !$lookup_opt;
if (defined($bki_values->{type_name})
and $bki_values->{type_name} ne 'oracharchar'
and $bki_values->{type_name} ne 'oracharbyte'
and $bki_values->{type_name} ne 'oravarcharchar'
and $bki_values->{type_name} ne 'oravarcharbyte'
and $bki_values->{type_name} ne 'oradate'
and $bki_values->{type_name} ne 'oratimestamp'
and $bki_values->{type_name} ne 'oratimestamptz'
and $bki_values->{type_name} ne 'oratimestampltz'
and $bki_values->{type_name} ne 'yminterval'
and $bki_values->{type_name} ne 'dsinterval'
and $bki_values->{type_name} ne 'number'
and $bki_values->{type_name} ne 'binary_float'
and $bki_values->{type_name} ne 'binary_double'
)
{
warn sprintf
"invalid zero OID reference in %s.dat field %s line %s\n",
$catname, $attname, $bki_values->{line_number}
if !$lookup_opt;
}
Comment on lines +1121 to +1141
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Zero‑OID warning is now completely suppressed when type_name is undefined

The new condition:

if (defined($bki_values->{type_name})
    and $bki_values->{type_name} ne 'oracharchar'
    ...
    and $bki_values->{type_name} ne 'binary_double')
{
    warn sprintf "invalid zero OID reference ...\n"
      if !$lookup_opt;
}

means that for any row where type_name is not set (which is true for most catalogs), zero or '-' OID placeholders will no longer produce an "invalid zero OID reference" warning at all. That’s a broader behavioral change than “suppress warnings for these specific Oracle types” and may hide genuinely invalid zero OID references in other catalogs.

If the intent is “suppress only for the listed Oracle types, keep existing behavior everywhere else (including when type_name is absent)”, the condition should be inverted to treat the whitelist as exceptions, for example:

-           if (defined($bki_values->{type_name}) 
-           and $bki_values->{type_name} ne 'oracharchar' 
-           and $bki_values->{type_name} ne 'oracharbyte' 
-           and $bki_values->{type_name} ne 'oravarcharchar' 
-           and $bki_values->{type_name} ne 'oravarcharbyte' 
-           and $bki_values->{type_name} ne 'oradate' 
-           and $bki_values->{type_name} ne 'oratimestamp' 
-           and $bki_values->{type_name} ne 'oratimestamptz' 
-           and $bki_values->{type_name} ne 'oratimestampltz' 
-           and $bki_values->{type_name} ne 'yminterval' 
-           and $bki_values->{type_name} ne 'dsinterval' 
-           and $bki_values->{type_name} ne 'number' 
-           and $bki_values->{type_name} ne 'binary_float' 
-           and $bki_values->{type_name} ne 'binary_double' 
-           )
-           {
-               warn sprintf
-                 "invalid zero OID reference in %s.dat field %s line %s\n",
-                 $catname, $attname, $bki_values->{line_number}
-                 if !$lookup_opt;
-           }
+           if (!$lookup_opt
+               && (!defined $bki_values->{type_name}
+                   || ($bki_values->{type_name} ne 'oracharchar'
+                       && $bki_values->{type_name} ne 'oracharbyte'
+                       && $bki_values->{type_name} ne 'oravarcharchar'
+                       && $bki_values->{type_name} ne 'oravarcharbyte'
+                       && $bki_values->{type_name} ne 'oradate'
+                       && $bki_values->{type_name} ne 'oratimestamp'
+                       && $bki_values->{type_name} ne 'oratimestamptz'
+                       && $bki_values->{type_name} ne 'oratimestampltz'
+                       && $bki_values->{type_name} ne 'yminterval'
+                       && $bki_values->{type_name} ne 'dsinterval'
+                       && $bki_values->{type_name} ne 'number'
+                       && $bki_values->{type_name} ne 'binary_float'
+                       && $bki_values->{type_name} ne 'binary_double')))
+           {
+               warn sprintf
+                 "invalid zero OID reference in %s.dat field %s line %s\n",
+                 $catname, $attname, $bki_values->{line_number};
+           }

This keeps the warning for all non‑whitelisted types and for rows without type_name, while silencing it only for the explicit Oracle compatibility types.

For readability/maintainability, you might also consider a small whitelist hash instead of a long chain of string comparisons:

my %zero_oid_ok_type = map { $_ => 1 } qw(
    oracharchar oracharbyte oravarcharchar oravarcharbyte
    oradate oratimestamp oratimestamptz oratimestampltz
    yminterval dsinterval number binary_float binary_double
);

...

if (!$lookup_opt
    && (!defined $bki_values->{type_name}
        || !$zero_oid_ok_type{$bki_values->{type_name}}))
{
    warn sprintf "invalid zero OID reference in %s.dat field %s line %s\n",
        $catname, $attname, $bki_values->{line_number};
}
🤖 Prompt for AI Agents
In src/backend/catalog/genbki.pl around lines 1121-1141, the current condition
requires type_name to be defined before warning, which suppresses zero‑OID
warnings for rows with no type_name; change the logic to treat the listed Oracle
types as exceptions instead of requiring type_name be present: warn on invalid
zero OID when lookup_opt is false and the type is not in the explicit whitelist
(or when type_name is undefined), i.e. build a small whitelist (hash or list) of
allowed type names and only skip the warning if the current type_name is in that
whitelist; update the conditional accordingly to restore warnings for rows
lacking type_name while silencing them for the explicit Oracle types.

}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utils/adt/arrayfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ ReadArrayDimensions(char **srcptr, int *ndim_p, int *dim, int *lBound,
if (!ReadDimensionInt(&p, &ub, origStr, escontext))
return false;
if (p == q) /* no digits? */
return(escontext, false,
ereturn(escontext, false,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("malformed array literal: \"%s\"", origStr),
errdetail("Missing array dimension value.")));
Expand Down
8 changes: 4 additions & 4 deletions src/backend/utils/adt/ruleutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -14410,7 +14410,7 @@ pg_get_function_arg_reference_typerowtype_internal(Tuplestorestate **tupstore,
{
RangeVar *rel = makeRangeVar(NULL, NULL, typeName->location);
char *field = NULL;
Oid relid;
Oid relid_1;
AttrNumber attnum;

/* deconstruct the name list */
Expand Down Expand Up @@ -14447,12 +14447,12 @@ pg_get_function_arg_reference_typerowtype_internal(Tuplestorestate **tupstore,
break;
}

relid = RangeVarGetRelid(rel, NoLock, true);
attnum = get_attnum(relid, field);
relid_1 = RangeVarGetRelid(rel, NoLock, true);
attnum = get_attnum(relid_1, field);

if (attnum != InvalidAttrNumber)
{
get_atttypetypmodcoll(relid, attnum,
get_atttypetypmodcoll(relid_1, attnum,
&fieldTypeId, &fieldTypMod, &fieldCollation);

/* this construct should never have an array indicator */
Expand Down
24 changes: 12 additions & 12 deletions src/bin/psql/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3601,7 +3601,7 @@ get_hostvariables(const char *sql, bool *error)
HostVariable *host = NULL;
char *newsql = NULL;
char *ptr = NULL;
int i = 0;
int j = 0;

*error = false;
if (!sql)
Expand All @@ -3610,12 +3610,12 @@ get_hostvariables(const char *sql, bool *error)
/* double write quote */
newsql = pg_malloc0(strlen(sql) * 2); /* enough */
ptr = newsql;
while (sql[i] != '\0')
while (sql[j] != '\0')
{
if (sql[i] == '\'')
*ptr++ = sql[i];
*ptr++ = sql[i];
i++;
if (sql[j] == '\'')
*ptr++ = sql[j];
*ptr++ = sql[j];
j++;
}
*ptr = '\0';

Expand Down Expand Up @@ -3695,7 +3695,7 @@ SendQuery_PBE(const char *query, HostVariable *hv)
PGTransactionStatusType transaction_status;
double elapsed_msec = 0;
bool OK = false;
int i;
int i = 0;
bool on_error_rollback_savepoint = false;
static bool on_error_rollback_warning = false;

Expand Down Expand Up @@ -3802,7 +3802,7 @@ SendQuery_PBE(const char *query, HostVariable *hv)
struct _variable **bindvar;
char *p = NULL;
bool missing = false;
int i;
int j;
instr_time before,
after;

Expand All @@ -3816,13 +3816,13 @@ SendQuery_PBE(const char *query, HostVariable *hv)
* the order of detection in the Oracle error message is from the
* back to the front.
*/
for (i = hv->length; i > 0; i--)
for (j = hv->length; j > 0; j--)
{
p = hv->hostvars[i - 1].name;
p = hv->hostvars[j - 1].name;
p++; /* skip colon */
bindvar[i - 1] = BindVariableExist(pset.vars, p);
bindvar[j - 1] = BindVariableExist(pset.vars, p);

if (bindvar[i - 1] == NULL)
if (bindvar[j - 1] == NULL)
{
missing= true;
break;
Expand Down
11 changes: 6 additions & 5 deletions src/fe_utils/string_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ getFmtEncoding(void)
const char *
fmtIdEnc(const char *rawid, int encoding)
{
if (DB_ORACLE == db_mode)
return ora_fmtId(rawid);

PQExpBuffer id_return = getLocalPQExpBuffer();

PQExpBuffer id_return;
const char *cp;
bool need_quotes = false;
size_t remaining = strlen(rawid);

if (DB_ORACLE == db_mode)
return ora_fmtId(rawid);

id_return = getLocalPQExpBuffer();

/*
* These checks need to match the identifier production in scan.l. Don't
* use islower() etc.
Expand Down
48 changes: 24 additions & 24 deletions src/interfaces/libpq/ivy-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,10 @@ IvyreplaceParamTypeByOutParameter(IvyBindOutInfo *bindinfo, int nParams, Oid *pa
static Ivylist*
IvyaddValueToList(Ivylist *list, void *value)
{
Ivylist *pre = NULL;
Ivylist *tmp = NULL;
int find = 0;

if (list == NULL)
{
Ivylist *new = (Ivylist *) malloc(sizeof(Ivylist));
Expand All @@ -3014,10 +3018,6 @@ IvyaddValueToList(Ivylist *list, void *value)
return new;
}

Ivylist *pre = NULL;
Ivylist *tmp = NULL;
int find = 0;

for (tmp = list, pre = list; tmp != NULL; pre = tmp, tmp = tmp->next)
{
if (tmp->value == value)
Expand Down Expand Up @@ -3763,7 +3763,7 @@ Ivyreplacenamebindtoposition(Ivyconn *tconn,
size_t size_error_buf,
bool *iscallinto)
{
int i;
int i = 0;
Ivyresult *res;
IvyBindOutNameInfo *tmp;

Expand All @@ -3787,7 +3787,7 @@ Ivyreplacenamebindtoposition(Ivyconn *tconn,
char *convertcall = NULL;
char *newsql = NULL;
char *ptr = NULL;
int i = 0;
int j = 0;

query_len = (stmtHandle->query_len * 2) + strlen("select * from get_parameter_description(") + 5;
query = (char *) malloc(query_len);
Expand All @@ -3800,12 +3800,12 @@ Ivyreplacenamebindtoposition(Ivyconn *tconn,

newsql = malloc(stmtHandle->query_len * 2); /* enough */
ptr = newsql;
while (stmtHandle->query[i] != '\0')
while (stmtHandle->query[j] != '\0')
{
if (stmtHandle->query[i] == '\'')
*ptr++ = stmtHandle->query[i];
*ptr++ = stmtHandle->query[i];
i++;
if (stmtHandle->query[j] == '\'')
*ptr++ = stmtHandle->query[j];
*ptr++ = stmtHandle->query[j];
j++;
}
*ptr = '\0';

Expand Down Expand Up @@ -3965,14 +3965,14 @@ Ivyreplacenamebindtoposition(Ivyconn *tconn,

stmtHandle->paramNames = (char **) malloc(sizeof(char *) * (n_tuples - 1));
memset(stmtHandle->paramNames, 0x00, sizeof(char *) * (n_tuples - 1));
for (i = 1; i < n_tuples; i++)
for (j = 1; j < n_tuples; j++)
{
int position;
char *name;
size_t name_len;

position = atoi(Ivygetvalue(res, i, 1)) - 1;
name = Ivygetvalue(res, i, 0);
position = atoi(Ivygetvalue(res, j, 1)) - 1;
name = Ivygetvalue(res, j, 0);

if (stmtHandle->paramNames[position] != NULL)
goto error_handle;
Expand Down Expand Up @@ -4055,9 +4055,9 @@ Ivyreplacenamebindtoposition2(Ivyconn *tconn,
IvyPreparedStatement *stmtHandle,
IvyError *errhp)
{
int i;
Ivyresult *res;
IvyBindNameInfo *tmp;
int i = 0;

if (stmtHandle->paramNames == NULL)
{
Expand All @@ -4072,7 +4072,7 @@ Ivyreplacenamebindtoposition2(Ivyconn *tconn,
char *convertcall = NULL;
char *newsql = NULL;
char *ptr = NULL;
int i = 0;
int j = 0;

query_len = (strlen(stmtHandle->query) * 2) + strlen("select * from get_parameter_description(") + 5;
query = (char *) malloc(query_len);
Expand All @@ -4086,12 +4086,12 @@ Ivyreplacenamebindtoposition2(Ivyconn *tconn,

newsql = malloc(strlen(stmtHandle->query) * 2); /* enough */
ptr = newsql;
while (stmtHandle->query[i] != '\0')
while (stmtHandle->query[j] != '\0')
{
if (stmtHandle->query[i] == '\'')
*ptr++ = stmtHandle->query[i];
*ptr++ = stmtHandle->query[i];
i++;
if (stmtHandle->query[j] == '\'')
*ptr++ = stmtHandle->query[j];
*ptr++ = stmtHandle->query[j];
j++;
}
*ptr = '\0';

Expand Down Expand Up @@ -4233,14 +4233,14 @@ Ivyreplacenamebindtoposition2(Ivyconn *tconn,
stmtHandle->paramNames = (char **) malloc(sizeof(char *) * (n_tuples - 1));
stmtHandle->nParams = n_tuples - 1;
memset(stmtHandle->paramNames, 0x00, sizeof(char *) * (n_tuples - 1));
for (i = 1; i < n_tuples; i++)
for (j = 1; j < n_tuples; j++)
{
int position;
char *name;
size_t name_len;

position = atoi(Ivygetvalue(res, i, 1)) - 1;
name = Ivygetvalue(res, i, 0);
position = atoi(Ivygetvalue(res, j, 1)) - 1;
name = Ivygetvalue(res, j, 0);

if (stmtHandle->paramNames[position] != NULL)
goto error_handle;
Expand Down
12 changes: 6 additions & 6 deletions src/pl/plisql/src/pl_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,21 +1094,21 @@ do_compile(FunctionCallInfo fcinfo,
* and the function returned datatype.
*
*/
char **argtypenames = NULL;
char *rettypename = NULL;
argtypenames = NULL;
rettypename = NULL;

get_func_typename_info(procTup, &argtypenames, &rettypename);
if (argtypenames != NULL)
{
int i = 0;
int j = 0;

for (i = 0; i < procStruct->pronargs; i++)
for (j = 0; j < procStruct->pronargs; j++)
{
if (strcmp(argtypenames[i], "") != 0)
if (strcmp(argtypenames[j], "") != 0)
{
TypeName *typeName;

typeName = (TypeName *) stringToNode(argtypenames[i]);
typeName = (TypeName *) stringToNode(argtypenames[j]);
plisql_add_type_referenced_objects(typeName);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/pl/plisql/src/pl_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ _PG_init(void)
/*
* Cleanup: deregister internal routines.
*/
void _PG_fini(void);

void
_PG_fini(void)
{
Expand Down
4 changes: 2 additions & 2 deletions src/pl/plisql/src/pl_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static int plisql_yyleng;
/* Current token's code (corresponds to plisql_yylval and plisql_yylloc) */
static int plisql_yytoken;

static yyscan_t plisql_scanner;
//static yyscan_t plisql_scanner;

/* The semantic value of the lookahead symbol. */
static YYSTYPE plisql_yylval;
Expand All @@ -140,7 +140,7 @@ static TokenAuxData pushback_auxdata[MAX_PUSHBACKS];
/* State for plisql_location_to_lineno() */
static const char *cur_line_start;
static const char *cur_line_end;
static int cur_line_num;
//static int cur_line_num;

/*
* yylex used global variable in pl_scanner.c
Expand Down
2 changes: 1 addition & 1 deletion src/pl/plisql/src/pl_subproc_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ plisql_build_variable_from_funcargs(PLiSQL_subproc_function * subprocfunc, bool
{
char buf[32];
PLiSQL_type *argdtype;
PLiSQL_variable *argvariable;
//PLiSQL_variable *argvariable;
PLiSQL_nsitem_type argitemtype;
Oid argtypeid = subprocfunc->rettype->typoid;

Expand Down