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
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get update
sudo apt-get install -y gcc-14 g++-14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100
sudo apt-get install -y build-essential git lcov bison flex \
libkrb5-dev libssl-dev libldap-dev libpam-dev python3-dev \
tcl-dev libperl-dev gettext libxml2-dev libxslt-dev \
Expand All @@ -35,4 +38,4 @@ jobs:
--with-ossp-uuid --with-libxml --with-libxslt --with-perl \
--with-icu --with-libnuma --enable-injection-points
- name: compile
run: make
run: make CFLAGS="$CFLAGS -Wshadow=compatible-local -Werror=missing-variable-declarations -Werror=maybe-uninitialized -Werror=unused-value -Werror=unused-but-set-variable -Werror=missing-prototypes -Werror=unused-variable"
4 changes: 2 additions & 2 deletions contrib/gb18030_2022/utf8_and_gb18030_2022.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

PG_MODULE_MAGIC;

gb18030_2022_to_utf8_hook_type pre_gb18030_2022_to_utf8_hook = NULL;
utf8_to_gb18030_2022_hook_type pre_utf8_to_gb18030_2022_hook = NULL;
static gb18030_2022_to_utf8_hook_type pre_gb18030_2022_to_utf8_hook = NULL;
static utf8_to_gb18030_2022_hook_type pre_utf8_to_gb18030_2022_hook = NULL;

int gb18030_2022_to_utf8(const unsigned char *iso, int len,
unsigned char *utf, bool noError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static const int month_days[] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};

const char *const ora_days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
static const char *const ora_days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", NULL};

#define CASE_fmt_YYYY case 0: case 1: case 2: case 3: case 4: case 5: case 6:
Expand All @@ -169,7 +169,7 @@ const char *const ora_days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
#define CASE_fmt_HH case 27: case 28: case 29:
#define CASE_fmt_MI case 30:

const char *const date_fmt[] =
static const char *const date_fmt[] =
{
"Y", "Yy", "Yyy", "Yyyy", "Year", "Syyyy", "syear",
"I", "Iy", "Iyy", "Iyyy",
Expand All @@ -195,7 +195,7 @@ const char *const date_fmt[] =
#define CASE_timezone_10 case 15: case 16:
#define CASE_timezone_11 case 17:

const char *const date_timezone[] =
static const char *const date_timezone[] =
{
"GMT", "ADT", "NST", "AST", "EDT", "CDT",
"EST", "CST", "MDT", "MST", "PDT", "PST",
Expand Down
17 changes: 11 additions & 6 deletions contrib/uuid-ossp/uuid-ossp.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,20 @@ Datum
ora_sys_guid(PG_FUNCTION_ARGS)
{
bytea *result;
#ifdef HAVE_UUID_OSSP
uuid_t *uuid;
uuid_rc_t rc;
#elif defined(HAVE_UUID_E2FS)
uuid_t uu;
#else /* BSD */
int i;
unsigned char byte_array[SYS_GUID_LENGTH];
#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 @@ -576,17 +584,14 @@ ora_sys_guid(PG_FUNCTION_ARGS)
memcpy(VARDATA(result), (unsigned char *)uuid, SYS_GUID_LENGTH);

#elif defined(HAVE_UUID_E2FS)
uuid_t uu;
uuid_generate_random(uu);
memcpy(VARDATA(result), uu, SYS_GUID_LENGTH);

#else /* BSD */
int i;
unsigned char byte_array[SYS_GUID_LENGTH];
for (i = 0; i < SYS_GUID_LENGTH; i++) {
byte_array[i] = (unsigned char)arc4random();
}
memcpy(VARDATA(result), byte_array, SYS_GUID_LENGTH);
#endif
PG_RETURN_BYTEA_P(result);
}
}
2 changes: 1 addition & 1 deletion src/backend/access/transam/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
#include "utils/memutils.h"
#endif

extern int bootstrap_database_mode;

/* timeline ID to be used when bootstrapping */
#define BootstrapTimeLineID 1

Expand Down
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;
}
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/backend/commands/sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ typedef struct SeqTableData
typedef SeqTableData *SeqTable;

static HTAB *seqhashtab = NULL; /* hash table for SeqTable items */
int64 session_id = 0;
int32 scale_value = 0;
static int64 session_id = 0;
static int32 scale_value = 0;

/*
* last_used_seq is updated by nextval() to point to the last used
Expand Down Expand Up @@ -2399,7 +2399,7 @@ process_owned_by(Relation seqrel, List *owned_by, bool for_identity)
DependencyType deptype;
int nnames;
Relation tablerel;
AttrNumber attnum;
AttrNumber attnum = InvalidAttrNumber;
char *seqname;

deptype = for_identity ? DEPENDENCY_INTERNAL : DEPENDENCY_AUTO;
Expand Down
3 changes: 2 additions & 1 deletion src/backend/commands/tablecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -15667,7 +15667,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype,
ScanKeyData key[3];
SysScanDesc scan;
HeapTuple depTup;
ObjectFunOrPkg *dependentFuncPkgOids;
ObjectFunOrPkg *dependentFuncPkgOids = NULL;
bool FuncPkgDepend = false;

if(NULL != numDependentFuncPkgOids &&
Expand All @@ -15678,6 +15678,7 @@ RememberAllDependentForRebuilding(AlteredTableInfo *tab, AlterTableType subtype,
dependentFuncPkgOids = *dependentFuncPkg;
}


Assert(subtype == AT_AlterColumnType || subtype == AT_SetExpression);

depRel = table_open(DependRelationId, RowExclusiveLock);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/executor/execExpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5112,7 +5112,7 @@ ExecInitFuncWithOutParams(Expr *node, ExprState *state,
{
FuncExpr *funcexpr = (FuncExpr *) node;
Oid funcOid = funcexpr->funcid;
HeapTuple func_tuple;
HeapTuple func_tuple = NULL;
Oid *argtypes = NULL;
char **argnames = NULL;
char *argmodes = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/oracle_parser/liboracle_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PG_MODULE_MAGIC_EXT(
static raw_parser_hook_type prev_raw_parser = NULL;
static get_keywords_hook_type prev_pg_get_keywords = NULL;
static fill_in_constant_lengths_hook_type prev_fill_in_contant_lengths = NULL;
quote_identifier_hook_type prev_quote_identifier = NULL;
static quote_identifier_hook_type prev_quote_identifier = NULL;

void _PG_init(void);
void _PG_fini(void);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/parser/parse_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ typedef struct OraParamNumbers
struct OraParamNumbers* prev;
}OraParamNumbers;

OraParamNumbers *TopOraParamNode = NULL;
OraParamNumbers *CurrentOraParamNode = NULL;
static OraParamNumbers *TopOraParamNode = NULL;
static OraParamNumbers *CurrentOraParamNode = NULL;

/*
* dynamic sql stmt parse information
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
1 change: 0 additions & 1 deletion src/backend/utils/adt/ruleutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -14410,7 +14410,6 @@ pg_get_function_arg_reference_typerowtype_internal(Tuplestorestate **tupstore,
{
RangeVar *rel = makeRangeVar(NULL, NULL, typeName->location);
char *field = NULL;
Oid relid;
AttrNumber attnum;

/* deconstruct the name list */
Expand Down
6 changes: 3 additions & 3 deletions src/backend/utils/misc/ivy_guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ int identifier_case_switch = INTERCHANGE;
bool identifier_case_from_pg_dump = false;
bool enable_case_switch = true;

char *nls_territory = "AMERICA";
char *nls_currency = "$";
char *nls_iso_currency = "AMERICA";
static char *nls_territory = "AMERICA";
static char *nls_currency = "$";
static char *nls_iso_currency = "AMERICA";

bool enable_emptystring_to_NULL = false;

Expand Down
2 changes: 1 addition & 1 deletion src/bin/pg_dump/pg_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -19124,7 +19124,7 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo)
default_minv = is_ascending ? 1 : PG_INT64_MIN;
default_maxv = is_ascending ? PG_INT64_MAX : -1;
}
else if (db_mode == DB_PG)
else
{
pg_fatal("unrecognized sequence type: %d", seq->seqtype);
default_minv = default_maxv = 0; /* keep compiler quiet */
Expand Down
18 changes: 8 additions & 10 deletions src/bin/psql/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3636,7 +3636,6 @@ get_hostvariables(const char *sql, bool *error)
HostVariable *host = NULL;
char *newsql = NULL;
char *ptr = NULL;
int i = 0;

*error = false;
if (!sql)
Expand All @@ -3645,12 +3644,13 @@ 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 != '\0')
{
if (sql[i] == '\'')
*ptr++ = sql[i];
*ptr++ = sql[i];
i++;
if (*sql == '\'')
*ptr++ = *sql;
*ptr++ = *sql;
sql++;
}
*ptr = '\0';
Comment on lines 3645 to 3655
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 | 🔴 Critical

Buffer overflow: allocation is 1 byte short.

The allocation at line 3645 is insufficient. In the worst case where sql contains all single quotes, the loop will write 2 * strlen(sql) characters, then attempt to write a null terminator at index 2 * strlen(sql), which is out of bounds.

Apply this diff to fix the allocation:

-	newsql = pg_malloc0(strlen(sql) * 2);	/* enough */
+	newsql = pg_malloc0(strlen(sql) * 2 + 1);	/* enough for worst case + null terminator */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
newsql = pg_malloc0(strlen(sql) * 2); /* enough */
ptr = newsql;
while (sql[i] != '\0')
while (*sql != '\0')
{
if (sql[i] == '\'')
*ptr++ = sql[i];
*ptr++ = sql[i];
i++;
if (*sql == '\'')
*ptr++ = *sql;
*ptr++ = *sql;
sql++;
}
*ptr = '\0';
newsql = pg_malloc0(strlen(sql) * 2 + 1); /* enough for worst case + null terminator */
ptr = newsql;
while (*sql != '\0')
{
if (*sql == '\'')
*ptr++ = *sql;
*ptr++ = *sql;
sql++;
}
*ptr = '\0';
🤖 Prompt for AI Agents
In src/bin/psql/common.c around lines 3645-3655, the buffer allocation
pg_malloc0(strlen(sql) * 2) is one byte too small because the loop can write 2 *
strlen(sql) characters plus the terminating NUL; change the allocation to
reserve space for the terminator (e.g., pg_malloc0(strlen(sql) * 2 + 1)) so the
final NUL fits, keeping the rest of the loop logic unchanged.


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

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

Expand All @@ -3851,7 +3849,7 @@ 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 (int i = hv->length; i > 0; i--)
{
p = hv->hostvars[i - 1].name;
p++; /* skip colon */
Expand Down Expand Up @@ -4039,7 +4037,7 @@ SendQuery_PBE(const char *query, HostVariable *hv)

/* reset \crosstabview trigger */
pset.crosstab_flag = false;
for (i = 0; i < lengthof(pset.ctv_args); i++)
for (int i = 0; i < lengthof(pset.ctv_args); i++)
{
pg_free(pset.ctv_args[i]);
pset.ctv_args[i] = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/psql/psqlplusscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static const PsqlScanKeyword psqlplus_keywords[] = {
PSQL_KEYWORD("variable", K_VARIABLE, UNRESERVED_PSQL_KEYWORD)
};

const int NumKeywords = lengthof(psqlplus_keywords);
static const int NumKeywords = lengthof(psqlplus_keywords);

/*
* Set the type of YYSTYPE.
Expand Down
4 changes: 2 additions & 2 deletions src/bin/psql/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ main(int argc, char *argv[])
}
else if (cell->action == ACT_SINGLE_SLASH)
{
PsqlScanState scan_state;
ConditionalStack cond_stack;
PsqlScanState scan_state = NULL;
ConditionalStack cond_stack = NULL;

pg_logging_config(PG_LOG_FLAG_TERSE);

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
2 changes: 1 addition & 1 deletion src/include/utils/ora_compatible.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ typedef enum
NLS_LENGTH_BYTE,
NLS_LENGTH_CHAR
} NlsLengthSemantics;

extern int bootstrap_database_mode;
#endif /* ORA_COMPATIBLE_H */
Loading