Unpredictable GPGME bug
Robert J. Hansen
rjhansen at inav.net
Mon May 27 13:11:01 CEST 2002
Looks like there might be a bug in GPGME (I know, pre-1.0 software with
bugs--what's the world coming to?). My C++ bindings for GPGME attempt to
grab all sorts of string data for a given key, and sometimes it will be
able to grab a string representation of the algorithm type and other times
it'll segfault. The offending snippet of code looks like:
GpgmeKey _key;
std::string _algo;
_algo = gpgme_key_get_string_attr(_key, GPGME_ATTR_ALGO, NULL, 0);
... Maybe one time in ten, that line of code will segfault.
gpgme_key_get_string_attr apparently returns a NULL pointer, and trying to
make a C++ std::string out of a NULL pointer is an instant segfault.
This has happened for other string quantities, such as usernames, etc.
For now, my solution is to assign the result of g_k_g_s_a() to a const
char*, test the const char* against NULL, and then assign either the const
char* to _algo or else assign "Unassigned" to _algo. However, this is
fairly inelegant given that we could just fix the GPGME code. :)
More information about the Gnupg-devel
mailing list