sivadeilra / win_etw

22 stars 2 forks source link

Events using &OsStr don't seem to serialize properly #4

Open jrmuizel opened 4 years ago

jrmuizel commented 4 years ago

Running

use win_etw_macros::trace_logging_provider;
use std::ffi::OsStr;

#[trace_logging_provider(guid = "89d6f527-86d0-4da1-8b4b-b050159a1d96")]
pub trait MyAppEvents {
    #[event(opcode = 1)]
    fn database_connection_created(connection_id: u64, server: &OsStr);
    #[event(opcode = 2)]
    fn database_connection_closed(connection_id: u64);
    // ...
}

fn main() {
    let events = MyAppEvents::new();
    events.database_connection_created(None, 35, OsStr::new("foer"));
    events.database_connection_closed(None, 35);

shows up as

00000022    MyAppEvents 14796   14352   1   0   05\22\2020-20:41:31:607 {"connection_id":35,"server":"fo","meta":{"provider":"MyAppEvents","event":"database_connection_created","time":"2020-05-22T20:41:31.607","cpu":1,"pid":14796,"tid":14352,"channel":11,"level":4,"opcode":1}}

in TraceView. Notice that server comes out as "fo" instead of "foer".

rylev commented 4 years ago

I tracked this down to being caused by passing the wrong length value for a wide os string here. The comment next to the code seems to indicate that passing the number of wide chars and not the number of bytes (minus the null char) is the right thing to do, but this leads to the error reported above. When doubling this value, the correct message is displayed in TraceView.

sivadeilra commented 4 years ago

Thanks, I'll get this fixed.