Page MenuHome GnuPG

Calling gettext_use_utf8(1) for the main thread should enable UTF-8 for all later created secondary threads
Testing, NormalPublic

Description

The problem (in short):

  • On Windows, gpgme calls gettext_use_utf8(1) to force gpgrt to use UTF-8 for the translated error messages.
  • gpgrt stores the corresponding flag gt_use_utf8 in a thread-local storage object.
  • If a new thread is created DllMain allocates a new thread-local storage object and initializes the flag to 0.
  • If gpg_strerror_r is called from the new thread it returns the error message using native encoding.

I think new threads should inherit the value of the flag set for the main thread.

One could argue that this isn't a problem because translated error messages are only output by the main thread (in particular for GUI apps), but this assumption doesn't hold for debug output. And together with caching this makes Kleopatra show wrongly encoded error messages to its users. See T5960#188013 for more details.

Event Timeline

That is probably right for gpgme as used by kleopatra. However in gnupg we need to switch utf8 on and off.

Maybe we can use a value of 2 for use_utf8() to tell new threads to take the current value. This will require that you enable utf8 with the new value before any second thread is started because we need to set a global flag.

Using/setting a value of 2 would work for Kleopatra.

Alright: Call gettext_use_utf8 (3) to set the current thread to utf8 and init all new threads to utf8 as well. This function with that value (actually bit 1 is relevant) can be used several times but it will never switch back the initialization to utf8. However, switching back and force to utf8 per threads is still possible.

werner triaged this task as Normal priority.

@werner Would it be okay to call gettext_use_utf8 (3) in gpgme's do_subsystem_inits where we currently call gettext_use_utf8 (1)? See https://dev.gnupg.org/source/gpgme/browse/master/src/version.c$77

Okay. Done in gpgme for gpgrt >= 1.51 (T7188).

ikloecker changed the task status from Open to Testing.Aug 7 2024, 10:41 AM

Setting this to testing. Could be tested as described in https://dev.gnupg.org/T7188#188093 by verifying that the logged debug messages also use correct encoding.