diff --git a/mssql_python/pybind/connection/connection.cpp b/mssql_python/pybind/connection/connection.cpp index c90529ef..3311c697 100644 --- a/mssql_python/pybind/connection/connection.cpp +++ b/mssql_python/pybind/connection/connection.cpp @@ -173,16 +173,16 @@ SQLRETURN Connection::setAttribute(SQLINTEGER attribute, py::object value) { LOG("Setting SQL attribute"); SQLPOINTER ptr = nullptr; SQLINTEGER length = 0; + std::string buffer; // to hold sensitive data temporarily if (py::isinstance(value)) { int intValue = value.cast(); ptr = reinterpret_cast(static_cast(intValue)); length = SQL_IS_INTEGER; } else if (py::isinstance(value) || py::isinstance(value)) { - static std::vector buffers; - buffers.emplace_back(value.cast()); - ptr = const_cast(buffers.back().c_str()); - length = static_cast(buffers.back().size()); + buffer = value.cast(); // stack buffer + ptr = buffer.data(); + length = static_cast(buffer.size()); } else { LOG("Unsupported attribute value type"); return SQL_ERROR; @@ -195,6 +195,11 @@ SQLRETURN Connection::setAttribute(SQLINTEGER attribute, py::object value) { else { LOG("Set attribute successfully"); } + + // Zero out sensitive data if used + if (!buffer.empty()) { + std::fill(buffer.begin(), buffer.end(), static_cast(0)); + } return ret; }