Skip to content

Commit

Permalink
Fixed bug resulting in a segfault when using external authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-tuininga committed Dec 6, 2024
1 parent 893c1d4 commit 21ecd71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/src/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Version 5.4.1 (TBD)
size cannot be reliably determined by ODPI-C, which occurs when using
Oracle Client libraries 12.1 (or older) to connect to Oracle Database 12.2,
or later.
#) Fixed bug resulting in a segfault when using external authentication
(`python-oracledb issue 425
<https://github.com/oracle/python-oracledb/issues/425>`__).


Version 5.4.0 (November 5, 2024)
Expand Down
15 changes: 12 additions & 3 deletions src/dpiConn.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static int dpiConn__createStandalone(dpiConn *conn, const char *userName,
static int dpiConn__get(dpiConn *conn, const char *userName,
uint32_t userNameLength, const char *password, uint32_t passwordLength,
const char *connectString, uint32_t connectStringLength,
const dpiCommonCreateParams *commonParams,
dpiConnCreateParams *createParams, dpiPool *pool, dpiError *error);
static int dpiConn__getHandles(dpiConn *conn, dpiError *error);
static int dpiConn__getServerCharset(dpiConn *conn, dpiError *error);
Expand All @@ -50,6 +51,7 @@ static int dpiConn__getSession(dpiConn *conn, uint32_t mode,
static int dpiConn__setAttributesFromCreateParams(dpiConn *conn, void *handle,
uint32_t handleType, const char *userName, uint32_t userNameLength,
const char *password, uint32_t passwordLength,
const dpiCommonCreateParams *commonParams,
const dpiConnCreateParams *params, int *used, dpiError *error);
static int dpiConn__setShardingKey(dpiConn *conn, void **shardingKey,
void *handle, uint32_t handleType, uint32_t attribute,
Expand Down Expand Up @@ -426,7 +428,7 @@ int dpiConn__create(dpiConn *conn, const dpiContext *context,
createParams->superShardingKeyColumns) {
status = dpiConn__get(conn, userName, userNameLength, password,
passwordLength, connectString, connectStringLength,
createParams, pool, error);
commonParams, createParams, pool, error);
} else {
status = dpiConn__createStandalone(conn, userName, userNameLength,
password, passwordLength, connectString, connectStringLength,
Expand Down Expand Up @@ -499,7 +501,7 @@ static int dpiConn__createStandalone(dpiConn *conn, const char *userName,
// populate attributes on the session handle
if (dpiConn__setAttributesFromCreateParams(conn, conn->sessionHandle,
DPI_OCI_HTYPE_SESSION, userName, userNameLength, password,
passwordLength, createParams, &used, error) < 0)
passwordLength, commonParams, createParams, &used, error) < 0)
return DPI_FAILURE;

// set the session handle on the service context handle
Expand Down Expand Up @@ -603,6 +605,7 @@ void dpiConn__free(dpiConn *conn, dpiError *error)
static int dpiConn__get(dpiConn *conn, const char *userName,
uint32_t userNameLength, const char *password, uint32_t passwordLength,
const char *connectString, uint32_t connectStringLength,
const dpiCommonCreateParams *commonParams,
dpiConnCreateParams *createParams, dpiPool *pool, dpiError *error)
{
int externalAuth, status;
Expand Down Expand Up @@ -653,7 +656,7 @@ static int dpiConn__get(dpiConn *conn, const char *userName,
// set attributes for create parameters
if (dpiConn__setAttributesFromCreateParams(conn, authInfo,
DPI_OCI_HTYPE_AUTHINFO, userName, userNameLength, password,
passwordLength, createParams, &used, error) < 0) {
passwordLength, commonParams, createParams, &used, error) < 0) {
dpiOci__handleFree(authInfo, DPI_OCI_HTYPE_AUTHINFO);
return DPI_FAILURE;
}
Expand Down Expand Up @@ -1179,10 +1182,16 @@ static int dpiConn__setAppContext(void *handle, uint32_t handleType,
static int dpiConn__setAttributesFromCreateParams(dpiConn *conn, void *handle,
uint32_t handleType, const char *userName, uint32_t userNameLength,
const char *password, uint32_t passwordLength,
const dpiCommonCreateParams *commonParams,
const dpiConnCreateParams *params, int *used, dpiError *error)
{
uint32_t purity;

// the handle is required for all external authentication scenarios except
// when token authentication is being used
if (params->externalAuth && (!commonParams || !commonParams->accessToken))
*used = 1;

// set credentials
if (userName && userNameLength > 0) {
if (dpiOci__attrSet(handle, handleType, (void*) userName,
Expand Down

2 comments on commit 21ecd71

@tgulacsi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did got SIGSEGV with godror using ODPI 5.4.0, but didn't see any change related creating new connections.
(Standalone connection with extrrnal auth).
So, this bug has been introduced with the token authentication?

@anthony-tuininga
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was introduced in 5.4.0 with this commit: f453aee. It was intended to resolve an issue with IAM token authentication but uncovered another bug in the Oracle Client libraries that caused this segfault. This commit resolves that issue.

Please sign in to comment.