Skip to content

Pass SQLSetDescRec field values correctly#186

Open
jarvis24young wants to merge 1 commit into
postgresql-interfaces:mainfrom
jarvis24young:fix-setdescrec-field-values
Open

Pass SQLSetDescRec field values correctly#186
jarvis24young wants to merge 1 commit into
postgresql-interfaces:mainfrom
jarvis24young:fix-setdescrec-field-values

Conversation

@jarvis24young
Copy link
Copy Markdown
Contributor

Summary

PGAPI_SetDescRec() forwards its arguments to PGAPI_SetDescField(), whose descriptor setters expect scalar descriptor values to be encoded in the SQLPOINTER argument, while pointer descriptor fields must receive the application pointer itself.

The old code passed addresses of local variables for both cases:

  • scalar fields such as SQL_DESC_TYPE, SQL_DESC_OCTET_LENGTH, SQL_DESC_PRECISION, and SQL_DESC_SCALE received &Type, &Length, etc.
  • SQL_DESC_DATA_PTR received &Data instead of Data

This could leave an ARD record with an invalid C type or a data pointer to a stack slot rather than the caller's output buffer.

This patch passes scalar values in the same form already expected by PGAPI_SetDescField(), and passes SQL_DESC_DATA_PTR as the caller's data buffer pointer.

Regression test

The existing descrec test now also covers SQLSetDescRec() on the application row descriptor:

  1. Get the statement ARD with SQLGetStmtAttr(SQL_ATTR_APP_ROW_DESC).
  2. Bind column 1 through SQLSetDescRec(..., SQL_C_CHAR, ..., value, &ind, &ind).
  3. Execute SELECT 42 and fetch the row.
  4. Verify the application buffer receives 42 and the indicator is 2.

Before the fix, the same black-box sequence failed at SQLFetch with SQLSTATE 07006 because the descriptor type was not stored as SQL_C_CHAR.

Verification

WSL ASan/UBSan build:

./runsuite descrec --inputdir=.
TAP version 13
1..1
ok 1 - descrec

Also ran git diff --check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant