What's wrong
LinuxSecretServiceCredentialStore.ThrowIfError (CredentialCache/Storage/LinuxSecretServiceCredentialStore.cs:142) reads the error message like this:
IntPtr messagePtr = Marshal.ReadIntPtr(error, IntPtr.Size * 2);
The glib layout is GError { GQuark domain /*uint32*/; gint code /*int32*/; gchar *message; }. So on 64-bit the message pointer is at offset 8, and the struct is 16 bytes long. IntPtr.Size * 2 is 16, which reads the word after the end of the struct. On 32-bit, IntPtr.Size * 2 happens to equal 8, which is why the bug is easy to miss.
Failure scenario (verified)
- A C program built against the system glib headers prints
sizeof(GError)=16 offsetof(message)=8.
- A .NET app created a real GError with
g_error_new_literal:
- reading at offset 8 returned the correct message;
- reading at offset 16 returned
0x20, which is the next malloc chunk's header;
- a verbatim copy of the
ThrowIfError extraction produced failed: ��.
The most common trigger is the one the class docs tell consumers to handle: a headless machine or container with no Secret Service running. The real libsecret error text is lost, the CredentialStoreException message is heap garbage, and if the stray value points at unmapped memory, PtrToStringUTF8 faults the process.
Suggested fix
Declare the struct and marshal it:
[StructLayout(LayoutKind.Sequential)]
private struct GError { public uint Domain; public int Code; public IntPtr Message; }
...
GError e = Marshal.PtrToStructure<GError>(error);
message = Marshal.PtrToStringUTF8(e.Message);
The minimal alternative is to read at sizeof(uint) + sizeof(int), which is 8 on both architectures.
Acceptance: on Linux x64 with no D-Bus session, the thrown exception carries libsecret's real message. For example, "Cannot autolaunch D-Bus without X11 $DISPLAY", or whatever the host reports.
What's wrong
LinuxSecretServiceCredentialStore.ThrowIfError(CredentialCache/Storage/LinuxSecretServiceCredentialStore.cs:142) reads the error message like this:The glib layout is
GError { GQuark domain /*uint32*/; gint code /*int32*/; gchar *message; }. So on 64-bit themessagepointer is at offset 8, and the struct is 16 bytes long.IntPtr.Size * 2is 16, which reads the word after the end of the struct. On 32-bit,IntPtr.Size * 2happens to equal 8, which is why the bug is easy to miss.Failure scenario (verified)
sizeof(GError)=16 offsetof(message)=8.g_error_new_literal:0x20, which is the next malloc chunk's header;ThrowIfErrorextraction producedfailed: ��.The most common trigger is the one the class docs tell consumers to handle: a headless machine or container with no Secret Service running. The real libsecret error text is lost, the
CredentialStoreExceptionmessage is heap garbage, and if the stray value points at unmapped memory,PtrToStringUTF8faults the process.Suggested fix
Declare the struct and marshal it:
The minimal alternative is to read at
sizeof(uint) + sizeof(int), which is 8 on both architectures.Acceptance: on Linux x64 with no D-Bus session, the thrown exception carries libsecret's real message. For example, "Cannot autolaunch D-Bus without X11 $DISPLAY", or whatever the host reports.