Pass SQLSetDescRec field values correctly#186
Open
jarvis24young wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PGAPI_SetDescRec()forwards its arguments toPGAPI_SetDescField(), whose descriptor setters expect scalar descriptor values to be encoded in theSQLPOINTERargument, while pointer descriptor fields must receive the application pointer itself.The old code passed addresses of local variables for both cases:
SQL_DESC_TYPE,SQL_DESC_OCTET_LENGTH,SQL_DESC_PRECISION, andSQL_DESC_SCALEreceived&Type,&Length, etc.SQL_DESC_DATA_PTRreceived&Datainstead ofDataThis 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 passesSQL_DESC_DATA_PTRas the caller's data buffer pointer.Regression test
The existing
descrectest now also coversSQLSetDescRec()on the application row descriptor:SQLGetStmtAttr(SQL_ATTR_APP_ROW_DESC).SQLSetDescRec(..., SQL_C_CHAR, ..., value, &ind, &ind).SELECT 42and fetch the row.42and the indicator is2.Before the fix, the same black-box sequence failed at
SQLFetchwith SQLSTATE07006because the descriptor type was not stored asSQL_C_CHAR.Verification
WSL ASan/UBSan build:
Also ran
git diff --check.