Invalid return from gpgme_op_keylist_next() + more

Nico Schottelius nico-gnupg-dev-0 at schottelius.org
Wed Jun 25 01:35:18 CEST 2008


Hello!

I am trying to create an application that uses libgpgme and I am
currently playing around with it.

Perhaps I am missing something, but this seems strange to me:

--------------------------------------------------------------------------------
[1:16] denkbrett:ceofhack% ./ceof_server           
Version: OpenPGP
gpgme_set_engine_info: ok
file=/usr/bin/gpg, home=/home/user/nico/.ceof/gnupg
err=0
C8697FED921C4699: nico schottelius <telmich at eof-1> (0)
err=117456895
zsh: segmentation fault  ./ceof_server
[1:16] denkbrett:ceofhack% 
--------------------------------------------------------------------------------

The relevant source code can be found it ceof_server.c [0], but is copied below:

--------------------------------------------------------------------------------
   gerr = gpgme_op_keylist_start(g_context, "nico schottelius", 0);
   if(gerr != GPG_ERR_NO_ERROR) return 11;

   i=0;
   while((gerr = gpgme_op_keylist_next(g_context, &g_recipient[0])) != GPG_ERR_EOF) {
      printf("err=%d\n", gerr);
      if(gerr == GPG_ERR_INV_VALUE) {
         printf("invalid pointer\n");
         return 15;
      } else if(gerr == GPG_ERR_ENOMEM) {
         printf("no mem\n");
         return 16;
      }

      printf ("%s: %s <%s> (%d)\n", g_recipient[0]->subkeys->keyid, g_recipient[0]->uids->name, g_recipient[0]->uids->email, i);
      i++;
   }
   g_recipient[1] = NULL;
--------------------------------------------------------------------------------

Why does gpgme_op_keylist_next return 117456895? Looks like something is overwritten.
There is only one subkey in that key.

I guess the segfault results from wrong data in g_recipient, that is used below:

--------------------------------------------------------------------------------
   gerr = gpgme_op_encrypt(g_context, g_recipient, 0, g_plain, g_encrypt);
   if(gerr != GPG_ERR_NO_ERROR) return 18;

   gerr = gpgme_op_decrypt(g_context, g_encrypt, g_plain);
   if(gerr != GPG_ERR_NO_ERROR) return 17;
--------------------------------------------------------------------------------

But that's not the real problem, I am curios why I get that strange gerr value.

Btw, in the infopage on my Debian lenny system of gpgme is no success return
code for gpgme_op_keylist_start() documentated.

Additionally, there is a broken example in the infopage:

--------------------------------------------------------------------------------
Wrong example in the infopage:

     gpgme_ctx_t ctx;
     gpgme_error_t err = gpgme_new (&ctx);

     if (!err)
       {
         err = gpgme_op_keylist_start (ctx, "g10code", 0);
         while (!err)
           {
             err = gpgme_op_keylist_next (ctx, &key);
             if (err)
               break;
             printf ("%s: %s <%s>\n", key->keyid, key->name, key->email);
             gpgme_key_release (key);
           }
         gpgme_release (ctx);
       }
     if (gpg_err_code (err) != GPG_ERR_EOF)

--------------------------------------------------------------------------------

If I c&p it, it results in:

--------------------------------------------------------------------------------
[0:31] denkbrett:ceofhack% make
gcc -D_FILE_OFFSET_BITS=64 -lgpgme -Wall -o ceof_server ceof_server.c
ceof_server.c: In function ‘main’:
ceof_server.c:102: error: ‘struct _gpgme_key’ has no member named ‘keyid’
ceof_server.c:102: error: ‘struct _gpgme_key’ has no member named ‘name’
ceof_server.c:102: error: ‘struct _gpgme_key’ has no member named ‘email’
make: *** [ceof_server] Fehler 1
--------------------------------------------------------------------------------

The debian packages:

--------------------------------------------------------------------------------
ii  libgpg-error-dev       1.4-2                  library for common error values and messages in GnuPG compon
ii  libgpg-error0          1.4-2                  library for common error values and messages in GnuPG compon
un  libgpgme-dev           <keine>                (keine Beschreibung vorhanden)
un  libgpgme10-dev         <keine>                (keine Beschreibung vorhanden)
ii  libgpgme11             1.1.6-2                GPGME - GnuPG Made Easy
ii  libgpgme11-dev         1.1.6-2                GPGME - GnuPG Made Easy
--------------------------------------------------------------------------------

In general it seems that the idea, to make gnupg easy is not quite well solved yet:

- why are there contextless and contextdependent functions? it would make life easier
  to have only contextdependent functions -> less confusing
- I am missing really simple functions. Imho encrypting a text for a person
  should be possible in two lines of code:

   gpgme_init(&context);
   gpgme_encrypt(context, char *fingerprint, void *datain, gpgme_data_t *dataencrypted)

- The documentation is missing a 5 minutes tutorial, that explains how to
   sign, encrypt, both,
   check sig, decrypt, both

- How to build gpgme from svn? I just git-svn cloned it, and ran automake:

   [1:32] denkbrett:gpgme% automake
   automake: `configure.ac' or `configure.in' is required

Just some impressions so far, perhaps I am missing some parts. But I look
forward to use gpgme.

Sincerly,

Nico

PS: What's the reason that http://lists.gnupg.org/pipermail/ gives a 403?
   (which is referred to by http://lists.gnupg.org/mailman/listinfo/gnupg-commits
    for instance)

[0]: http://unix.schottelius.org/cgi-bin/gitweb.cgi?p=EOF/ceofhack;a=summary

-- 
Think about Free and Open Source Software (FOSS).
http://nico.schottelius.org/documentations/foss/the-term-foss/

PGP: BFE4 C736 ABE5 406F 8F42  F7CF B8BE F92A 9885 188C
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: </pipermail/attachments/20080625/03449765/attachment-0001.pgp>


More information about the Gnupg-devel mailing list