Skip to content

Commit

Permalink
Merge branches 'oracle-fixes' and 'more-ubsan-fixes'
Browse files Browse the repository at this point in the history
Fixes for UB in Firebird and Oracle backends and other Oracle fixes for
non-ancient Oracle versions.

See #1177, #1178.
  • Loading branch information
vadz committed Nov 10, 2024
2 parents a339894 + 115663a commit ee5ce98
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ jobs:
fi
if [ "${{matrix.no_ubsan}}" = true ]; then
set_env_var SOCI_NO_UBSAN 1
else
set_env_var UBSAN_OPTIONS print_stacktrace=1:halt_on_error=1
fi
- name: Setup tmate
Expand Down
4 changes: 2 additions & 2 deletions include/soci/oracle/soci-oracle.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct oracle_standard_into_type_backend : details::standard_into_type_backend
OCIDefine *defnp_;
sb2 indOCIHolder_;
void *data_;
void *ociData_;
void *ociData_ = NULL;
char *buf_; // generic buffer
details::exchange_type type_;

Expand Down Expand Up @@ -143,7 +143,7 @@ struct oracle_standard_use_type_backend : details::standard_use_type_backend
OCIBind *bindp_;
sb2 indOCIHolder_;
void *data_;
void *ociData_;
void *ociData_ = NULL;
bool readOnly_;
char *buf_; // generic buffer
details::exchange_type type_;
Expand Down
6 changes: 4 additions & 2 deletions src/backends/firebird/blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ std::size_t firebird_blob_backend::read_from_start(void * buf, std::size_t toRea
// Ensure we don't read more than we have
toRead = std::min(toRead, size - offset);

std::memcpy(buf, &data_[offset], toRead);
if (toRead)
std::memcpy(buf, &data_[offset], toRead);

return toRead;
}
Expand Down Expand Up @@ -121,7 +122,8 @@ void firebird_blob_backend::trim(std::size_t newLen)
void firebird_blob_backend::writeBuffer(std::size_t offset,
const void * buf, std::size_t toWrite)
{
std::memcpy(data_.data() + offset, buf, toWrite);
if (toWrite)
std::memcpy(data_.data() + offset, buf, toWrite);
}

void firebird_blob_backend::open()
Expand Down
22 changes: 15 additions & 7 deletions src/backends/oracle/standard-into-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,23 @@ void oracle_standard_into_type_backend::post_fetch(

void oracle_standard_into_type_backend::clean_up()
{
if (type_ == x_xmltype || type_ == x_longstring)
if (ociData_)
{
free_temp_lob(statement_.session_, static_cast<OCILobLocator *>(ociData_));
ociData_ = NULL;
}
switch (type_)
{
case x_xmltype:
case x_longstring:
free_temp_lob(statement_.session_, static_cast<OCILobLocator *>(ociData_));
break;

case x_blob:
OCIDescriptorFree(ociData_, OCI_DTYPE_LOB);
break;

default:
throw soci_error("Internal error: OCI data used for unexpected type");
}

if (type_ == x_blob)
{
OCIDescriptorFree(ociData_, OCI_DTYPE_LOB);
ociData_ = NULL;
}

Expand Down
23 changes: 16 additions & 7 deletions src/backends/oracle/standard-use-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,23 @@ void oracle_standard_use_type_backend::post_use(bool gotData, indicator *ind)

void oracle_standard_use_type_backend::clean_up()
{
if (type_ == x_xmltype || type_ == x_longstring)
{
free_temp_lob(statement_.session_, static_cast<OCILobLocator *>(ociData_));
ociData_ = NULL;
}

if (type_ == x_blob)
if (ociData_)
{
switch (type_)
{
case x_xmltype:
case x_longstring:
free_temp_lob(statement_.session_, static_cast<OCILobLocator *>(ociData_));
break;

case x_blob:
// We don't own the LOB locator, oracle_blob_backend does.
break;

default:
throw soci_error("Internal error: OCI data used for unexpected type");
}

ociData_ = NULL;
}

Expand Down

0 comments on commit ee5ce98

Please sign in to comment.