odbc-api icon indicating copy to clipboard operation
odbc-api copied to clipboard

Cannot list iODBC drivers: Buffer must contain terminating zero

Open matthewgapp opened this issue 1 year ago • 3 comments

Getting Buffer must contain terminating zero. when trying to list drivers with the iodbc feature flag enabled on mac.

Minimal repro:

Step 1: enable the iodbc feature:

odbc-api = { version = "5.0.0", features = ["iodbc"] }

Step 2: run this code:

use odbc_api::Environment;

fn main() {
    let env = Environment::new().unwrap();
    let drivers = env.drivers();
    println!("Drivers: {:?}", drivers);
}

You'll get this error

thread 'main' panicked at /Users/matthewgapp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/odbc-api-5.0.0/src/handles/sql_char.rs:63:10:
Buffer must contain terminating zero.
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:72:14
   2: core::panicking::panic_display
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:168:5
   3: core::panicking::panic_str
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:152:5
   4: core::option::expect_failed
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/option.rs:1988:5
   5: core::option::Option<T>::expect
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/option.rs:898:21
   6: odbc_api::handles::sql_char::sz_to_utf8
             at /Users/matthewgapp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/odbc-api-5.0.0/src/handles/sql_char.rs:59:15
   7: odbc_api::handles::sql_char::SzBuffer::to_utf8
             at /Users/matthewgapp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/odbc-api-5.0.0/src/handles/sql_char.rs:174:9
   8: odbc_api::environment::Environment::drivers
             at /Users/matthewgapp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/odbc-api-5.0.0/src/environment.rs:520:35
   9: odbc_api_driver_bug_test::main
             at ./src/main.rs:5:19
  10: core::ops::function::FnOnce::call_once
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Some background: I'm trying to get iodbc to work on my mac because we need to connect to snowflake, which doesn't support unixodbc on mac. So downstream, I'm enabling the iodbc feature flag on. Would be very helpful to list out the drivers.

matthewgapp avatar Jan 15 '24 00:01 matthewgapp

This is a Bug in iodbc. It is with the implementation of SQLDrivers. In this case the pointer to the buffer passed to SQLDrivers did not as commended by the ODBC standard contain a zero terminated string after the call.

Nothing odbc-api can do about this. If you find an upstream issue of iodbc we can track here, or create one in their GitHub and want to link it here I would keep this issue open in order to do so. Otherwise I would close the issue.

pacman82 avatar Jan 16 '24 17:01 pacman82

This is a Bug in iodbc. It is with the implementation of SQLDrivers. In this case the pointer to the buffer passed to SQLDrivers did not as commended by the ODBC standard contain a zero terminated string after the call.

Nothing odbc-api can do about this. If you find an upstream issue of iodbc we can track here, or create one in their GitHub and want to link it here I would keep this issue open in order to do so. Otherwise I would close the issue.

Thank you for looking into it. I didn't find an existing issue so I created a new one https://github.com/openlink/iODBC/issues/98.

matthewgapp avatar Jan 17 '24 00:01 matthewgapp

thanks

pacman82 avatar Jan 17 '24 20:01 pacman82