Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More UBSAN fixes #1178

Merged
merged 3 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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