Message-ID: From: "jarvis24young (@jarvis24young)" To: "postgresql-interfaces/psqlodbc" Date: Tue, 28 Apr 2026 03:26:23 +0000 Subject: [postgresql-interfaces/psqlodbc] PR #178: Reject overlong cursor names List-Id: X-GitHub-Author-Id: 48787405 X-GitHub-Author-Login: jarvis24young X-GitHub-Issue: 178 X-GitHub-Repo: postgresql-interfaces/psqlodbc X-GitHub-State: merged X-GitHub-Type: pull_request X-GitHub-Url: https://github.com/postgresql-interfaces/psqlodbc/pull/178 Content-Type: text/plain; charset=utf-8 ## Summary This patch makes `SQLSetCursorName()` reject cursor names longer than the length advertised by the driver through `SQLGetInfo(SQL_MAX_CURSOR_NAME_LEN)`. The driver reports `MAX_CURSOR_LEN` (`32`) for `SQL_MAX_CURSOR_NAME_LEN`, but `PGAPI_SetCursorName()` previously accepted and stored longer application-provided cursor names. The new check validates the fully materialized cursor name before replacing the statement's current cursor name. ## Details `PGAPI_SetCursorName()` now: - builds the requested cursor name into a temporary buffer first; - reports `STMT_NO_MEMORY_ERROR` if allocation fails; - rejects names longer than `MAX_CURSOR_LEN` with `STMT_INVALID_CURSOR_NAME`; - only replaces `stmt->cursor_name` after allocation and validation both succeed. This keeps the statement state unchanged on failure and makes `SQLSetCursorName()` consistent with the driver's advertised ODBC cursor-name limit. ## Regression test The existing `cursor-name` black-box ODBC test now: - queries `SQL_MAX_CURSOR_NAME_LEN` from the connected driver; - builds an invalid cursor name with length `SQL_MAX_CURSOR_NAME_LEN + 1`; - verifies that `SQLSetCursorName()` rejects it; - verifies the diagnostic SQLSTATE is `34000`; - then continues through the existing valid cursor-name path. Verified in WSL against the unixODBC test path with an ASan/UBSan/gcov build: ```sh cd ~/psqlodbc-build make -j4 cd test make LIBODBC='-lodbc' exe/cursor-name-test ODBCSYSINI=. ODBCINSTINI=./odbcinst.ini ODBCINI=./odbc.ini \ ASAN_OPTIONS=verify_asan_link_order=0:detect_leaks=0 \ LD_PRELOAD=/lib/x86_64-linux-gnu/libasan.so.8 \ ./runsuite cursor-name --inputdir=. ``` Result: ```text TAP version 13 1..1 ok 1 - cursor-name ```