Heap OOB read (scanbuf-1) and empty prosrc when EOF immediately follows AS/IS in CREATE FUNCTION (oracle mode)
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Start in src/backend/oracle_parser/liboracle_parser.c and read set_oracle_plsql_body(), including the PACKAGE/TYPE BODY branch with the similar scan loop. Reproduce the EOF case in oracle mode using the SQL shown in the issue, then inspect the parser behavior and relevant tests. Done means EOF immediately after AS/IS reports a syntax error without an out-of-bounds read or creating a function with empty prosrc.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Environment
- IvorySQL master @
2c5e8dd(self-built from source) - Mode: oracle (
ivorysql.database_mode = oracle)
Steps to reproduce
-- oracle-mode port; note: no body, no terminator, EOF right after AS
CREATE OR REPLACE FUNCTION f() RETURN int AS
Actual behavior
WARNING: compilation error
HINT: syntax error at end of input
CREATE FUNCTION
The statement succeeds and an invalid function is created whose prosrc is the empty string:
SELECT length(prosrc) FROM pg_proc WHERE proname = 'f';
length | 0
Calling it then fails with ERROR: function f is in invalid state.
For comparison, a properly terminated function keeps its source
(prosrc = 'BEGIN RETURN 1; END', length 19).
Expected behavior
A syntax error (matching PostgreSQL semantics), and under no circumstances an out-of-bounds read.
Root cause analysis
In src/backend/oracle_parser/liboracle_parser.c, set_oracle_plsql_body() initializes the body position sentinel:
set_oracle_plsql_bodystart(yyscanner, -1, 0); /* body_start = -1 */
When EOF arrives immediately after AS/IS, cur_token == 0 on entry, so the token-scanning loop
while (cur_token != 0)
{
if (beginpos < 0)
beginpos = *llocp;
...
}
never executes and beginpos stays -1. The trailing guard
if ((cur_token == ';' && blocklevel == 0 && ...) ||
(cur_token == 0 && blocklevel > 0))
is also skipped (both disjuncts false), and execution falls through to:
lvalp->core_yystype.str = pstrdup(yyextra->core_yy_extra.scanbuf + beginpos); /* scanbuf - 1 */
i.e. pstrdup(scanbuf - 1) — a 1-byte heap buffer underflow read (the scan buffer is palloc(slen + 2)). Under ASAN this is a heap-buffer-underflow; in normal builds the byte happens to be \0, producing an empty string that is handed to the grammar as the function body SCONST, which is why the DDL silently "succeeds" with an empty prosrc.
The same pattern exists in the PACKAGE/TYPE BODY branch of the same function (pstrdup(... scanbuf + beginpos) after an identically structured loop, ~120 lines below).
Suggested fix
When cur_token == 0 && blocklevel == 0 on entry (or after the loop), report a proper syntax error instead of synthesizing an SCONST token from scanbuf + beginpos; alternatively guard beginpos >= 0 before the pstrdup.
- Vorherrschende Sprache
- C
- Sterne
- 1.1k
- Forks
- 232
- Ø Merge
- 2 T. 3 Std.
- Gemergte PRs (30 T.)
- 8
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus IvorySQL/IvorySQL
-
PostgreSQL::Version rejects documented full psql version outputEvtl. vergeben @feitiansiyan hat das vor 1 Tag übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
IvorySQL/IvorySQL#2999 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
UTL_FILE.NEW_LINE silently ignores negative line countsEvtl. vergeben @X-LightYear hat das vor 9 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
IvorySQL/IvorySQL#2634 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Character function regression assumes normal identifier case on default interchange clustersEvtl. vergeben @zhouxj52 hat das vor 16 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
IvorySQL/IvorySQL#2470 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
xml2 no-libxslt expected files do not match PG/Oracle input scriptsEvtl. vergeben @zhouxj52 hat das vor 16 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
IvorySQL/IvorySQL#2468 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Title: Build failure in DBMS_SCHEDULER due to incorrect placement of pg_noreturnEvtl. vergeben @darshan-s-44 hat das vor 22 Tagen übernommen. Offenbug good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in IvorySQL/IvorySQL
Ähnliche Issues
-
ai-driven-fuzzing bug claude Minor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
linagora/open-bastion#425 ·
Maintainer antworten meist innerhalb von 1 Tag
-
question
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 68/100
-
follow-up Prio 📌
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
moonbitlang/async#713 ·
Maintainer antworten meist innerhalb von 1 Tag
-
examples/dnsdoctor: cleanup.sh stops at the first missing piece of a setup.sh that did not finishOffenseverity: low
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
luainkernel/lunatik#2263 ·
Maintainer antworten meist innerhalb von 1 Tag